\documentclass{article}
\usepackage{tikz}
\begin{document}
% See also https://tex.stackexchange.com/questions/187356/
\begin{tikzpicture}
\node[align = left] at (0,6) {Line One\\Line Two\\ [Line Three]}; % <-- Problem
\node[align = left] at (0,4) {Line One\\Line Two\\ Line Three}; % <-- No Problem
\node[align = left] at (0,2) {Line One\\Line Two\\\relax [Line Three]}; % <-- No Problem
\node[align = left] at (0,0) {Line One\\Line Two\newline [Line Three]}; % <-- Problem
\end{tikzpicture}
% \linebreak\relax also does not work.
\end{document}
- I randomly found a problem in
tikztoday. - I want to have a line break within a
node. - When the line break
\\is before a square bracket[then I got an error (! Missing number, treated as zero.). - Searching the web brought me to Linebreak followed by bracket.
\\\relaxworks but\newlinedoes not work (\linebreak\relaxalso does not work).- Question: Is there a "best practice" to address this problem in a
tikz node?
PS: I also hope that this question helps others with the same problem to find this post.
tikzbut also happens outside.\\has an optional argument, a distance, e.g.\\[1em]. If you fill it with something different than a distance, this gives an error. You can use\\ \mbox{}[]or similar to avoid the problem. – Mar 27 '21 at 02:41\mbox) and the explanation that is has nothing to do withtikzin particular. – Dr. Manuel Kuehner Mar 27 '21 at 02:42Two\\ {[Line Three]};instead ofTwo\\ [Line Three];. This prevents the\\\treating the square bracket as the start of an optional parameter. – Peter Grill Mar 27 '21 at 03:06