# Standalone doesn't place properly the content

I'm trying to create many small pdf graphics such as this one:

\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 creates a pdf with size A4 and I later use pdfcrop.exe to remove the margins.

But I would prefer to do it on a single step, with standalone, but it doesn't work.

I've tried with:

\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}


But the image is not properly cut.

I've also tried with the solutions proposed here: Problem with content location with standalone package

%\documentclass[multi=minipage, border=0]{standalone}


or

%\documentclass[multi=varwidth, border=0]{standalone}


or

\usepackage[subpreambles=true]{standalone}


but it even worse

• I've icluded pictures showing it. I would like to get the whole table as in my first picture (manually cropped), but I just get broken tables or splitted on several pages. I mean I would like to get the same result as in my first picture but using standalone or some automatic method. – skan May 29 '18 at 11:29
• In the second example, changing the width of the minipage environment from 0.25\linewidth to 0.4\linewidthwould stop the lopping off of the material in the third column. – Mico May 29 '18 at 11:31
• @Mico OK, now it works a little bit better but still has some white margins beyond the limits of the table. – skan May 29 '18 at 11:42

You're adding spaces with the unprotected endlines in

\renewcommand{\arraystretch}{1.8}
\setlength\tabcolsep{10pt}


which you can avoid by placing the material before \begin{document}.

You can also avoid guessing the width with 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}


• Why do we use that strange % after \end{tcolorbox} ? – skan May 29 '18 at 13:21