我正在尝试创建许多小型 pdf 图形,例如这个:
\RequirePackage{luatex85}
\documentclass[11pt,a4paper]{article}
\usepackage[margin=0cm]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,decorations.markings,math,arrows.meta}
\usetikzlibrary{tikzmark}
\newcommand{\tablenode}[2]{\tikz[baseline=(#1.base),remember picture]\node[inner sep=1pt,name=#1]{#2};}
\usepackage{tcolorbox}
\begin{document}
\renewcommand{\arraystretch}{1.8}
\setlength\tabcolsep{10pt}
\noindent\begin{minipage}[b]{0.25\linewidth}
\begin{tcolorbox}[boxsep=0mm,title=Sample data, colback=blue!5!white,colframe=blue!75!black]
\begin{tabular}{lcl}
id & Type & Date \\
\hline
1 & \tablenode{1}{A} & 1980 \\
1 & \tablenode{2}{B} & 1991 \\
2 & \tablenode{3}{C} & 1978 \\
2 & \tablenode{4}{A} & 1990 \\
2 & \tablenode{5}{A} & 1998 \\
\end{tabular}
\end{tcolorbox}
\end{minipage}
\begin{tikzpicture}[remember picture,overlay,
hor/.style={shorten <=1pt, shorten >=2pt, -{Triangle[angle=80:4pt]}, color=green!60!black!85, line width=2pt},
hor2/.style={shorten <=1pt, shorten >=2pt, -{Triangle[angle=80:4pt]}, color=red!70!black!85!, line width=2pt}]
\draw [hor] (1) -- (2);
\draw [hor] (3) -- (4);
\draw [hor] (4) -- (5);
\end{tikzpicture}
\end{document}
Luatex 创建了一个 A4 尺寸的 pdf,然后我使用 pdfcrop.exe 删除边距。
但是我更愿意通过独立的单步方式来完成它,但是这并不奏效。
我尝试过:
\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,decorations.markings,math,arrows.meta}
\usetikzlibrary{tikzmark}
\newcommand{\tablenode}[2]{\tikz[baseline=(#1.base),remember picture]\node[inner sep=1pt,name=#1]{#2};}
\usepackage{tcolorbox}
\begin{document}
...
\end{document}
我也尝试过这里提出的解决方案: 独立包的内容定位问题
%\documentclass[multi=minipage, border=0]{standalone}
或者
%\documentclass[multi=varwidth, border=0]{standalone}
或者
\usepackage[subpreambles=true]{standalone}
答案1
您正在添加未受保护的结束线空格
\renewcommand{\arraystretch}{1.8}
\setlength\tabcolsep{10pt}
您可以通过将材料放在前面来避免这种情况\begin{document}
。
您还可以避免猜测宽度hbox
:
\documentclass{standalone}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,decorations.markings,math,arrows.meta}
\usetikzlibrary{tikzmark}
\newcommand{\tablenode}[2]{\tikz[baseline=(#1.base),remember picture]\node[inner sep=1pt,name=#1]{#2};}
\usepackage{tcolorbox}
\tcbuselibrary{fitting}
\renewcommand{\arraystretch}{1.8}
\setlength\tabcolsep{10pt}
\begin{document}
\begin{tcolorbox}[hbox,boxsep=0mm,title=Sample data, colback=blue!5!white,colframe=blue!75!black]
\begin{tabular}{lcl}
id & Type & Date \\
\hline
1 & \tablenode{1}{A} & 1980 \\
1 & \tablenode{2}{B} & 1991 \\
2 & \tablenode{3}{C} & 1978 \\
2 & \tablenode{4}{A} & 1990 \\
2 & \tablenode{5}{A} & 1998 \\
\end{tabular}
\end{tcolorbox}% <---- don't forget
\begin{tikzpicture}[remember picture,overlay,
hor/.style={shorten <=1pt, shorten >=2pt, -{Triangle[angle=80:4pt]}, color=green!60!black!85, line width=2pt},
hor2/.style={shorten <=1pt, shorten >=2pt, -{Triangle[angle=80:4pt]}, color=red!70!black!85!, line width=2pt}]
\draw [hor] (1) -- (2);
\draw [hor] (3) -- (4);
\draw [hor] (4) -- (5);
\end{tikzpicture}
\end{document}