我一直在摆弄TikZ
节点以获取带框的文本(mdframed
框的一部分,但这不是重点),然后我发现了一些让我困惑的东西。如果您运行以下代码:
\documentclass{article}
\usepackage{tikz}
\begin{document}
with \verb|TikZ|:
\tikz{\node[draw]{t};}
\tikz{\node[draw]{t~};}
\tikz{\node[draw]{t~~};}
with \verb|\framebox|:
\framebox{t}
\framebox{t~}
\end{document}
你得到:
~
我一直想知道后面的第一个空格( )t
去哪儿了?相反,\framebox
似乎尊重这个强制性的空间。
这里发生了什么事?
答案1
如有疑问,请添加\tracingall
。如果您修改输入以说
{\tracingall\tikz{\node[draw]{t~};}}
对于第二种情况,你会得到下面的日志,
~->\nobreakspace {}
\nobreakspace ->\protect \nobreakspace
{\relax}
\nobreakspace ->\leavevmode \nobreak \
\leavevmode ->\unhbox \voidb@x
{\unhbox}
\nobreak ->\penalty \@M
{\penalty}
{\ }
{begin-group character {}
{end-group character }}
{end-group character }}
{restoring \tikz@align@header=undefined}
{restoring \graph=macro:->\path graph}
{restoring \datavisualization=macro:->\tikz@lib@datavisualization }
{restoring \calendar=macro:->\tikz@lib@cal@calendar }
{restoring \matrix=macro:->\tikz@path@overlay {node[matri\ETC.}
{restoring \coordinate=macro:->\tikz@path@overlay {coordinate\ETC.}
{restoring \node=macro:->\tikz@path@overlay {node}}
{restoring \useasboundingbox=macro:->\path [use as bounding box]}
{restoring \clip=macro:->\path [clip]}
{restoring \shadedraw=macro:->\path [shade,draw]}
{restoring \shade=macro:->\path [shade]}
{restoring \filldraw=macro:->\path [fill,draw]}
{restoring \fill=macro:->\path [fill]}
{restoring \pattern=macro:->\path [pattern]}
{restoring \draw=macro:->\path [draw]}
{restoring \againpath=macro:#1->\pgfextra {\pgfsyssoftpath@getcurrentpath \ETC.
}
{restoring \path=macro:->\let \tikz@signal@path =\tikz@signal@path \ETC.}
{restoring \stopscope=macro:->\tikz@atend@scope \iftikz@transparency@group \ETC
.}
{restoring \startscope=macro:->\pgfutil@ifnextchar [\tikz@@scope@env \ETC.}
{restoring \endscope=macro:->\tikz@atend@scope \iftikz@transparency@group \ETC.
}
{restoring \scope=macro:->\pgfutil@ifnextchar [\tikz@@scope@env \ETC.}
{restoring \pgfsysprotocol@temp=macro:->{q }}
{restoring \pgf@colnext=\relax}
{restoring \pgf@coltest=macro:->}
{restoring \pgf@colmarshal=macro:->\pgfsys@color@gray {0}}
{restoring \\color@pgf@tempcolor=macro:->\xcolor@ {}{0 g 0 G}{gray}{0}}
{restoring \reserved@c=macro:->\XC@definec@lor []{pgf@tempcol\ETC.}
{restoring \@let@token=the letter n}
{restoring \reserved@b=macro:->\XC@definec@lor []{pgf@tempcol\ETC.}
{restoring \reserved@a=macro:->\XC@definec@lor []{pgf@tempcol\ETC.}
{\unskip}
这表明,扩展~
Tikz 后会结束一个组(因此 TeX 会恢复大量定义)并且 unskip 原语(来自\unskip
)会删除空格。
这类似于 LaTeXtabular
单元格定义,用于\unskip
删除内容中的尾随空格,但 LaTeX 框命令不会执行此操作。请注意,\unskip
只删除一个跳过,因此~~
第二个跳过被删除,但第一个跳过仍保留。