tikz 中用于括号装饰的多行文本

tikz 中用于括号装饰的多行文本

我正在尝试通过 tikZ 制作带有事件的时间线。一切都很顺利,我在这里找到了一些很好的例子和解释,但是......我为带有长“标题”的时间线做了一个括号装饰。我试图让这个标题有多行,但不起作用。例如,在节点的文本中,我可以将文本放入\\文本中,这样文本就会变成两行。但这种方法在文本中对于括号装饰完全没用。最小示例如下

\documentclass[a4paper,12pt,oneside,titlepage]{report} \usepackage{tikz} \usetikzlibrary{snakes, positioning, decorations.pathreplacing, calc} \tikzset{ date labels/.style = { % Font font = \sffamily, % Anchor anchor = north, %Angle %rotate = 45 } } \tikzset{ event/.style = { %Shape rectangle, % Size rounded corners = 2mm, % Border thick, draw = #1!50, %Filling fill = #1!20, % Font align = center, font = \sffamily\scriptsize, } } \tikzset{ side labels/.style = { %Shape rectangle, % Size minimum size = 6mm, rounded corners = 2mm, % Border very thick, draw = black!50, %Filling top color = white, bottom color = black!20, % Font font = \sffamily, % Anchor anchor = east, } } \begin{document} \begin{tikzpicture}[line width = 1pt] \node [side labels] at (-1, 0) {Customer A}; \draw[fill = black!100] {[snake] (0, 0)circle[radius=2pt] -- (2, 0)circle[radius=2pt]} -- (7, 0)circle[radius=2pt] -- (9, 0)circle[radius=2pt]; \draw (0, -0.05) node [date labels] {1} -- (0, 0.05) node (paid_date) {}; \draw (2, -0.05) node [date labels] {30} -- (2, 0.05) node (paid_back_date) {}; \draw (7, -0.05) node [date labels] {280} -- (7, 0.05) node (next_paid_date) {}; \draw (9, -0.05) node [date labels] {365} -- (9, 0.05) node (stop_date) {}; \begin{scope}[on grid] \node (utility_first) [event = gray] at (-1, 1.25) {$1^{st}$ loan\\utilization}; \draw [gray!50] (utility_first) -- (paid_date); \node (start_monitoring) [event = gray] at (1, 1.25) {start\\monitoring}; \draw [gray!50] (start_monitoring) -- (paid_date); \node (paid_back) [event = gray] at (2.75, 1.25) {$1^{st}$ loan\\paid back}; \draw [gray!50] (paid_back) -- (paid_back_date); \node (utility_second) [event = gray] at (7, 1.25) {$2^{nd}$ loan\\utilization}; \draw [gray!50] (utility_second) -- (next_paid_date); \node (stop_monitoring) [event = gray] at (9, 1.25) {stop\\monitoring}; \draw [gray!50] (stop_monitoring) -- (stop_date); \end{scope} \draw [decorate, decoration = {brace, amplitude = 10pt, mirror}, xshift = 0pt, yshift = -42pt] ($(paid_back_date.south) + (0, -0.5)$) -- ($(stop_date.south) + (0, -0.5)$) node [black, midway, xshift = 0cm, yshift = -0.6cm] {\scriptsize ``real'' $2^{nd}$ loan utilization period under monitoring = $335$ days}; \end{tikzpicture} \end{document}

我想要的是将括号的标题显示为两行而不是一行。如能得到任何帮助我将不胜感激!

答案1

有两种可能性:您可以text width=<length>为节点指定一个,如果文本超出范围,它将自动中断文本<length>,或者您可以提供一个align=<alignment option>并使用手动中断文本\\

因此,

node [align=center,midway,anchor=north,yshift=-1.5ex,font=\scriptsize] { ``real'' $2^{nd}$ loan utilization period\\under monitoring = $335$ days};

或者

node [align=center,text width=5cm,midway,anchor=north,yshift=-1.5ex,font=\scriptsize] {``real'' $2^{nd}$ loan utilization period under monitoring = $335$ days};   

将产生

相关内容