TikZ 節點不允許換行?

TikZ 節點不允許換行?

當我嘗試在 Ti 中新增換行符時出現錯誤kZ 節點。任何想法?

代碼:

\documentclass[12pt,dvipsnames]{article}
\usepackage[a4paper, bindingoffset=0.1in, left=1in, right=1in, 
top=.51in, bottom=1in, footskip=.25in]{geometry}
\usepackage{listings,xcolor,amssymb,tikz,amsmath,enumitem}  
\usetikzlibrary{shadows.blur, shapes.arrows, shapes.geometric, shapes.misc}
\begin{document}
\tikzset{decision/.style= {diamond, draw, aspect=2,text badly centered, node
distance=2.5em, inner sep=0pt}}
\begin{center}
  \begin{tikzpicture}
    \node[decision] (dic) at (0,0) {\scriptsize{is $dE<0$}};
    \node[decision](metro) at (-3,-2) {\scriptsize{is\\ $rand< e^{-\Delta E/k_BT}$}};
  \end{tikzpicture}
\end{center}
\end{document}

錯誤

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.12 ...sion](metro) at (-3,-2) {\scriptsize{is\\ 
                                                  $rand< e^{-\Delta E/k_BT}$}};

答案1

您需要新增對齊(例如center)以允許\\節點內容。

\documentclass[12pt,dvipsnames]{article}
\usepackage[a4paper, bindingoffset=0.1in, left=1in, right=1in, 
top=.51in, bottom=1in, footskip=.25in]{geometry}
\usepackage{listings,xcolor,amssymb,tikz,amsmath,enumitem}  
\usetikzlibrary{shadows.blur, shapes.arrows, shapes.geometric, shapes.misc}
\begin{document}
\tikzset{decision/.style= {diamond, draw, aspect=2,text badly centered, node
distance=2.5em, inner sep=0pt,font=\scriptsize,align=center}}
\begin{center}
  \begin{tikzpicture}
    \node[decision] (dic) at (0,0) {is $\mathrm{d}E<0$}; 
    \node[decision](metro) at (-3,-2) {is\\ $\text{rand}< e^{-\Delta E/k_\mathrm{B}T}$}; 
   \end{tikzpicture}
\end{center}
\end{document}

在此輸入影像描述

相關內容