Graphics, Figures & Tablestick label with comma causes error

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
nikio
Posts: 8
Joined: Thu Jan 25, 2024 10:26 am

tick label with comma causes error

Post by nikio »

Hello,
have a strange problem running the following code: this works

Code: Select all

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{amssymb} %carica anche amsfonfts
\usepackage{pgfplots}
\pgfplotsset{width=20cm,height=7cm,compat=1.9}
\usetikzlibrary{arrows.meta,angles,quotes,decorations}
\begin{document}
	\begin{tikzpicture}
	\begin{axis}[
		height=5cm,
		axis equal,
		width=6cm,
		axis x line=center,
		axis y line=center,
		xmin=-6, xmax=5,
		ymin=-6, ymax=4,
		xtick={0,4},
		ytick={0,3},
		extra x ticks={-6},
		extra x tick style={xticklabel style={above, yshift=1mm}},
		extra y ticks={-4.5},
		extra y tick labels={$-4.5$},
		extra y tick style={yticklabel style={right, xshift=1mm}},
		xlabel={$x$},
		ylabel={$y$},
		ylabel style={yshift=2mm},
		]
		\coordinate (O) at (axis cs:0,0);
		\coordinate (A) at (axis cs:4,0);
		\coordinate (B) at (axis cs:4,3);
		\coordinate (C) at (axis cs:0,3);
		\coordinate (mA) at (axis cs:-6,0);
		\coordinate (mB) at (axis cs:-6,-4.5);
		\coordinate (mC) at (axis cs:0,-4.5);
		\draw[-{Stealth}, color=black, line width=0.5pt] {(O) -- (B)};
		\draw[ color=black,dashed, line width=0.5pt] {(A) -- (B)};
		\draw[ color=black,dashed, line width=0.5pt] {(C) -- (B)};
		\node[right, xshift=1mm,align=left, inner sep=0] at (B){$\vec{v}$};
		\draw[-{Stealth}, color=red, line width=0.5pt] {(O) -- (mB)};
		\draw[ color=black,dashed, line width=0.5pt] {(mA) -- (mB)};
		\draw[ color=black,dashed, line width=0.5pt] {(mC) -- (mB)};
		\node[below, xshift=0mm, yshift=-2mm,align=left, inner sep=0] at (mB){$-1,\!5\cdot \vec{v}$};%
	\end{axis}
\end{tikzpicture}
\end{document}

while this doesn't, the only modification (marked in the code) is a comma in the code for the tick label

Code: Select all

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{amssymb} %carica anche amsfonfts
\usepackage{pgfplots}
\pgfplotsset{width=20cm,height=7cm,compat=1.9}
\usetikzlibrary{arrows.meta,angles,quotes,decorations}
\begin{document}
	\begin{tikzpicture}
	\begin{axis}[
		height=5cm,
		axis equal,
		width=6cm,
		axis x line=center,
		axis y line=center,
		xmin=-6, xmax=5,
		ymin=-6, ymax=4,
		xtick={0,4},
		ytick={0,3},
		extra x ticks={-6},
		extra x tick style={xticklabel style={above, yshift=1mm}},
		extra y ticks={-4.5},
		extra y tick labels={$-4,5$},% <<<<<------ ONLY CHANGE the comma: 4,5 instead of 4.5
		extra y tick style={yticklabel style={right, xshift=1mm}},
		xlabel={$x$},
		ylabel={$y$},
		ylabel style={yshift=2mm},
		]
		\coordinate (O) at (axis cs:0,0);
		\coordinate (A) at (axis cs:4,0);
		\coordinate (B) at (axis cs:4,3);
		\coordinate (C) at (axis cs:0,3);
		\coordinate (mA) at (axis cs:-6,0);
		\coordinate (mB) at (axis cs:-6,-4.5);
		\coordinate (mC) at (axis cs:0,-4.5);
		\draw[-{Stealth}, color=black, line width=0.5pt] {(O) -- (B)};
		\draw[ color=black,dashed, line width=0.5pt] {(A) -- (B)};
		\draw[ color=black,dashed, line width=0.5pt] {(C) -- (B)};
		\node[right, xshift=1mm,align=left, inner sep=0] at (B){$\vec{v}$};
		\draw[-{Stealth}, color=red, line width=0.5pt] {(O) -- (mB)};
		\draw[ color=black,dashed, line width=0.5pt] {(mA) -- (mB)};
		\draw[ color=black,dashed, line width=0.5pt] {(mC) -- (mB)};
		\node[below, xshift=0mm, yshift=-2mm,align=left, inner sep=0] at (mB){$-1,\!5\cdot \vec{v}$};%
	\end{axis}
\end{tikzpicture}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

tick label with comma causes error

Post by Stefan Kottwitz »

Hi Nikio,

welcome to the forum!

Protect the comma by braces so it doesn't cause TikZ parsing issues:

Code: Select all

extra y tick labels={$-4{,}5$}
Stefan
LaTeX.org admin
nikio
Posts: 8
Joined: Thu Jan 25, 2024 10:26 am

tick label with comma causes error

Post by nikio »

Somewhat obscure but so simple!
These are the things that make make me think I'll never completely feel confident with latex: I didn't feel that tikz should parse something inside the math mode as a tikz command... and I don't really understand why it isn't parsed if it's in braces.
Thank you for your guidance!
Post Reply