
Чтобы настроить межстрочный интервал узла для многострочного текста, мне приходится начинать текст с \baselineskip=2.5ex
и добавлять дополнительный \par
после него внутри каждого узла. Есть ли способ избежать повторного выполнения этого?
\documentclass{report}
\usepackage{tikz}
\usetikzlibrary{calc,fit,positioning}
\begin{document}
\begin{tikzpicture}[
remember picture, overlay,
every node/.style={fill=green, font=\large}
]
\node (N0)
at (0,0)
{Start}; % <- That's what I want for multi-line text: Only the text
\node[right=of N0, text width=3cm, align=center] (N1)
{\baselineskip=2.5ex Looooooooooong multi-line text.\par}; % <- That's what's required
\node[right=of N1, text width=3cm, align=center] (N2)
{\baselineskip=2.5ex Another looooooooooong multi-line text.\par};
\end{tikzpicture}
\end{document}
Существуют ли параметры стиля узла для определения таких префиксных и постфиксных команд?Существуют postaction
и preactions
параметры, которые мне не помогают. Следующий код не создает правильный межстрочный интервал (кажется, \par
игнорируется).
%...
every node/.style={fill=green, font=\large, postaction={\par}}
%...
\node[right=of N1, text width=3cm, align=center] (N2)
{\baselineskip=2.5ex Another looooooooooong multi-line text.};
%...
Есть идеи?
решение1
Я не вижу необходимости в \par
, но вы можете использовать /tikz/execute at begin node
и /tikz/execute at end node
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
every node/.style={fill=green, font=\large},
execute at begin node={\baselineskip=5ex\relax},
% execute at end node={\endgraf}% not needed, as far as I can see
]
\node (N0) at (0,0) {Start};
\node[right=of N0, text width=3.2cm, align=center] (N1)
{Looooooooooong multi-line text.};
\node[right=of N1, text width=3.2cm, align=center] (N2)
{Another looooooooooong multi-line text.};
\end{tikzpicture}
\end{document}
Я удалил ненужный remember picture, overlay
, увеличил 3 см до 3,2 см, чтобы избежать переполнения \hbox
во втором узле, и увеличил ваш \baselineskip=2.5ex
to \baselineskip=5ex
, чтобы сделать его эффект более заметным. Гарантирует, \relax
что TeX не попытается расширить токены после 5ex
при чтении значения, назначенного \baselineskip
.
решение2
Вы можете использовать font
. Посмотрите, работает ли это для вас. Я использую , \baselineskip=5ex
чтобы подчеркнуть разницу.
\documentclass{report}
\usepackage{tikz}
\usetikzlibrary{calc,fit,positioning}
\begin{document}
\begin{tikzpicture}[
remember picture, overlay,
every node/.style={fill=green, font=\large},
baselineskip/.style={font={\large\baselineskip=#1}}
]
\node (N0)
at (0,0)
{Start}; % <- That's what I want for multi-line text: Only the text
\node[right=of N0, text width=3cm, align=center,baselineskip=5ex] (N1)
{Looooooooooong multi-line text.}; % <- That's what's required
\node[right=of N1, text width=3cm, align=center,baselineskip=5ex] (N2)
{Another looooooooooong multi-line text.};
\end{tikzpicture}
\end{document}