%-Zeichen innerhalb "symbolic x coords={..}"

Tabellen und Grafiken erstellen und anordnen


Thomsel

%-Zeichen innerhalb "symbolic x coords={..}"

Beitrag von Thomsel »

Hallo zusammen,

ich benötige eine kleine Hilfe bei der Beschriftung meines Diagramms.
Ich würde gerne innerhalb "symbolic x coords = ..." ein PROZENTZEICHEN (%) setzen.

Das Ergebnis sollte sein: Blabla Ma.-%

Aber iwie möchte er kein %-Zeichen zulassen.


Mein Minimalbeispiel:
\documentclass[12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

\usepackage{pgfplots}

\begin{document}

	\begin{figure}[htb]\centering
		\begin{tikzpicture}
 			 \begin{axis}[
    width=21cm,
    height=9.5cm,
    ybar=3pt, 
    bar width=30pt,
    nodes near coords,
    enlarge x limits=0.2,
    legend cell align=left,
    xtick={data},
    symbolic x coords={Blabla Ma.-},
    ymin=0,
    ymax=100,
    ytick={0,10,20,30,40,50,60,70,80,90,100}]

	%Daten
   \addplot[black,fill=lightgray,error bars/.cd,y dir=both,y explicit] coordinates {
      (Blabla Ma.-,10.29)};

 			\end{axis}
		\end{tikzpicture}
	\end{figure}

\end{document}

Kann mir da jmd weiterhelfen?
Vielen Dank!! :)

Gruß
Thommy

Gast

Beitrag von Gast »

In TeX leitet das Prozentzeichen einen Kommentar ein, daher muss Du ein Prozentzeichen, das Du ausgeben möchtest, mit \% escapen.
\documentclass[12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

\usepackage{pgfplots}
\makeatletter
\let\percent\@percentchar
\makeatother
\begin{document}

   \begin{figure}[htb]\centering
      \begin{tikzpicture}
           \begin{axis}[
    width=21cm,
    height=9.5cm,
    ybar=3pt,
    bar width=30pt,
    nodes near coords,
    enlarge x limits=0.2,
    legend cell align=left,
    xtick={data},
    symbolic x coords={Blabla Ma.-\%},
    ymin=0,
    ymax=100,
    ytick={0,10,20,30,40,50,60,70,80,90,100}]

   %Daten
   \addplot[black,fill=lightgray,error bars/.cd,y dir=both,y explicit] coordinates {
      (Blabla Ma.-\%,10.29)};

          \end{axis}
      \end{tikzpicture}
   \end{figure}

\end{document}
Siehe auch Sonderzeichen in LaTeX

Gast

Beitrag von Gast »

Ich sehe gerade, dass der Online-Editor von dem Code oben nicht ganz begeistert ist (der Block in \makeatletter/\\makeatother ist übrigens dort nicht nötig, das war noch über). Mit der neusten Version von PGFPlots (Version 3.12) geht es bei mir auf dem Rechner aber schon.

Das \let\percent\@percentchar kommt von How do I get a % sign in symbolic x coords in pgfplots
\documentclass[12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

\usepackage{pgfplots}
\makeatletter
\let\percent\@percentchar
\makeatother
\begin{document}

\begin{figure}[htb]\centering
\begin{tikzpicture}
\begin{axis}[
width=21cm,
height=9.5cm,
ybar=3pt,
bar width=30pt,
nodes near coords,
enlarge x limits=0.2,
legend cell align=left,
xtick={data},
symbolic x coords={Blabla Ma.-\percent},
ymin=0,
ymax=100,
ytick={0,10,20,30,40,50,60,70,80,90,100}]

%Daten
\addplot[black,fill=lightgray,error bars/.cd,y dir=both,y explicit] coordinates {
(Blabla Ma.-\percent,10.29)};

\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}
funktioniert auch mit der älteren Version von PGFPlots bei Overleaf.

Thomsel

Beitrag von Thomsel »

Vielen Dank! Das mit "\%" ist mir natürlich bekannt...

Aber dein Lösungsvorschlag mit
\makeatletter
\let\percent\@percentchar
\makeatother
und
\percent 

klappt super! Besten Dank! :)

Antworten