我一直认为独立版会在中心显示我的绘图,但下面的示例似乎被剪裁了(红线)。
\documentclass[border=5pt]{standalone}
\usepackage{tikz,booktabs,array}
\begin{document}
\tikzset{>=latex}
\tikzstyle{every picture}+=[remember picture,baseline]
\tikzstyle{every node}+=[inner sep=0pt,anchor=base,
minimum width=.5cm,align=center,text depth=.25ex,outer sep=1.5pt]
\tikzstyle{every path}+=[very thick]
\newcommand{\tikzmark}[2]{\tikz \node (#1) {#2};}
\begin{tabular}{|>{\bfseries}c|>{\bfseries}c|}
\toprule
\hline
\tikzmark{m00}{Number} & \tikzmark{m01}{Name} \\ \hline
\tikzmark{m10}{0} & \tikzmark{m11}{Jack} \\ \hline
\tikzmark{m20}{1} & \tikzmark{m21}{Mary} \\ \hline
\tikzmark{m30}{2} & \tikzmark{m31}{John} \\ \hline
\tikzmark{m40}{3} & \tikzmark{m41}{Alice} \\ \hline
\bottomrule
\end{tabular}
\begin{tikzpicture}[overlay,remember picture]
\coordinate (P) at ([xshift=20pt]m21.east);
\draw[red] (m11.east) -| (P);
\draw[->,red] (P) |- (m21.east);
\draw[red] (m31.east) -| (P);
\end{tikzpicture}
\end{document}
答案1
您可以在 末尾添加一个水平空格tabular
。下面我添加了\hspace*{15pt}
以下内容:
笔记:
您的代码中有几个多余的空格,导致输出中出现额外的空格。我删除了它们。对于极端情况,请参见Tex 容量超出范围(如果在使用宏后删除%)。
您应该使用
tikzset
而不是tikzstyle
:应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式?
代码:
\documentclass[border=5pt]{standalone}
\usepackage{tikz,booktabs,array}
\begin{document}
\tikzset{>=latex}%
\tikzstyle{every picture}+=[remember picture,baseline]%
\tikzstyle{every node}+=[inner sep=0pt,anchor=base,
minimum width=.5cm,align=center,text depth=.25ex,outer sep=1.5pt]%
\tikzstyle{every path}+=[very thick]%
%
\newcommand{\tikzmark}[2]{\tikz \node (#1) {#2};}%
%
\begin{tabular}{|>{\bfseries}c|>{\bfseries}c|}
\toprule
\hline
\tikzmark{m00}{Number} & \tikzmark{m01}{Name} \\ \hline
\tikzmark{m10}{0} & \tikzmark{m11}{Jack} \\ \hline
\tikzmark{m20}{1} & \tikzmark{m21}{Mary} \\ \hline
\tikzmark{m30}{2} & \tikzmark{m31}{John} \\ \hline
\tikzmark{m40}{3} & \tikzmark{m41}{Alice} \\ \hline
\bottomrule
\end{tabular}%
%
\begin{tikzpicture}[overlay,remember picture]
\coordinate (P) at ([xshift=20pt]m21.east);
\draw[red] (m11.east) -| (P);
\draw[->,red] (P) |- (m21.east);
\draw[red] (m31.east) -| (P);
\end{tikzpicture}%
\hspace*{15pt}%
\end{document}