我想知道如何使用 tikz 在旋转节点内获得换行符。我尝试将选项align=center
与一起使用\rotatebox{}{}
,但出现错误。这是一个有效代码的示例,但没有换行符:
\begin{figure}[h!tp]
\begin{tikzpicture}[generaloptions/.style 2 args={
draw,ultra thick,font={\bfseries},inner sep=0,outer sep=0,minimum height=#1,minimum width=#2}]
\node[generaloptions={3.5cm}{1.5cm},align=center,anchor=south west,font=\footnotesize\bfseries] (l1) at ([xshift=-1.5cm]big.south west) {\rotatebox{90}{Line Break}};
\end{tikzpicture}
\end{figure}
我想要这样的东西但我却收到一个错误:
\begin{figure}[h!tp]
\begin{tikzpicture}[generaloptions/.style 2 args={
draw,ultra thick,font={\bfseries},inner sep=0,outer sep=0,minimum height=#1,minimum width=#2}]
\node[generaloptions={3.5cm}{1.5cm},align=center,anchor=south west,font=\footnotesize\bfseries] (l1) at ([xshift=-1.5cm]big.south west) {\rotatebox{90}{Line \\ Break}};
\end{tikzpicture}
\end{figure}
我是不是遗漏了什么?谢谢!
答案1
rotatebox
尝试将里面的所有东西都旋转,就像一个盒子一样。因此你不能指望换行。你可以将内容放在parbox
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[generaloptions/.style 2 args={
draw,ultra thick,font={\bfseries},inner sep=0,outer sep=0,minimum height=#1,minimum width=#2}]
\node[generaloptions={3.5cm}{1.5cm},align=center,anchor=south west,font=\footnotesize\bfseries] (l1) at (0,0) {\rotatebox{90}{\parbox[c]{1.5cm}{\centering Line Break}}};
\end{tikzpicture}
\end{document}
如果您想要单独旋转文本并且使用换行符,您可以使用该选项rotate=90,text width = 1.5cm
(并放弃rotatebox
):
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[generaloptions/.style 2 args={
draw,ultra thick,font={\bfseries},inner sep=0,outer sep=0,minimum height=#1,minimum width=#2}]
\node[generaloptions={1.5cm}{3.5cm},text width = 1.5cm,align=center,anchor=south west,font=\footnotesize\bfseries,rotate=90] (l1) at (0,0) {Line Break and break yes };
\end{tikzpicture}
\end{document}
不过,您可能必须互换minimum height
和minimum width
。