1

Trying to generate a tikz diagram using tikzcd package in a standalone document so that no excess white space and page header/footer is added around the diagram.

\documentclass[tikz, margin=1mm]{standalone}
\usepackage{tikz-cd}
\usetikzlibrary{arrows,arrows.meta}

\begin{document}
\tikzcdset{arrow style=tikz, diagrams={>=stealth}}
\begin{tikzpicture}
\begin{tikzcd}[column sep=normal]
                    & A \arrow[dl] & \\
  B \arrow[rr] \arrow[ur, "a", dashed, xshift=-2ex, yshift=0.5ex] &                            & C
\end{tikzcd}
\qquad
\begin{tikzcd}[column sep=normal]
& A \arrow[dr] & \\
B \arrow[rr] & & C \arrow[ul, "b", swap, dashed, xshift=2ex, yshift=0.5ex]
\end{tikzcd}
\end{tikzpicture}

\end{document}

However, only part of the diagram is generated. Changing the document class to 'article' generates the full diagram. Is tikzcd not compatible with the 'standalone' class? If so, how can I create a diagram using tikzcd without excess white space and page header/footer etc?

0
3

You should never nest a tikzpicture inside another tikzpicture; a tikzcd is a tikzpicture. This thoroughly confuses standalone when trying to determine the bounding box.

Also remove the tikz option, that tries to make an image out of every tikzpicture in the document body.

Edited version, where the \tikzcdset instruction has been moved to the preamble so as not to create spurious spaces; the same for \qquad moved next to \end{tikzcd}. Also tikz-cd loads the arrows and arrows.meta libraries.

\documentclass[margin=1mm]{standalone}
\usepackage{tikz-cd}

\tikzcdset{arrow style=tikz, diagrams={>=stealth}}

\begin{document}
\begin{tikzcd}[column sep=normal]
& A \arrow[dl] & \\
B \arrow[rr] \arrow[ur, "a", dashed, xshift=-2ex, yshift=0.5ex] & & C
\end{tikzcd}\qquad
\begin{tikzcd}[column sep=normal]
& A \arrow[dr] & \\
B \arrow[rr] & & C \arrow[ul, "b", swap, dashed, xshift=2ex, yshift=0.5ex]
\end{tikzcd}

\end{document}

enter image description here

1
  • Thanks for the pointers!
    – Skyork
    Jul 8 '19 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.