19

I'd like to be able to scale some rather complex CDs using the scale key, for example scale=0.5. In the following MWE the scale key seems to have no effect.

\documentclass{amsart}

\usepackage{tikz}
\usepackage{tikz-cd}

\usetikzlibrary{matrix}

\begin{document}

%% Uncomment/comment appropriately:
%\begin{tikzpicture}[column sep=1in,row sep=1in,scale=0.5in]
\begin{tikzpicture}[column sep=1in,row sep=1in]
    \matrix (A) [matrix of math nodes]
    {
        A& B\\
        C& D\\
    };
    \draw[->] (A-1-1) -- (A-1-2);
    \draw[->] (A-1-1) -- (A-2-1);
    \draw[->] (A-2-1) -- (A-2-2);
    \draw[->] (A-2-2) -- (A-1-2);
\end{tikzpicture}

%% Uncommenting the scale option has no effect:
\begin{tikzcd}%[scale=0.5]
    A\ar{r}\ar{d}&B\\
    C\ar{r}&D\ar{u}\\
\end{tikzcd}

\end{document}

These are very simple examples, and I could easily alter the appropriate dimensions, but the CDs on which I am working are complex and carefully arranged -- I'd rather just be able to scale them if at all possible.

2
  • The column seps and row seps are not scaleble in the same way as many other things in TikZ. You can however try something like \tikzset{scale seps/.style={column sep/.expanded={(#1)*(\pgfmatrixcolumnsep)}, row sep/.expanded={(#1)*(\pgfmatrixrowsep)}}}. tikz-cd also has a few named seps, e.g. row sep=large. Commented Oct 15, 2013 at 15:34
  • If you really want to scale a diagram (which is typographically a questionable thing to do), you can simply change the font size: \[\small\begin{tikzcd} ... \end{tikzcd}\]. In tex.stackexchange.com/questions/198499/…, more options for squeezing a wide diagram are discussed.
    – Augusto
    Commented Nov 1, 2014 at 14:56

3 Answers 3

16

It seems tikzcd environment doesn't take the scale argument. Since you are loadin tikz, you can put tikzcd inside a node and that takes a scale argument. (I accept that this a over kill / ugly hack, but things work that way some times)

\documentclass{amsart}
\usepackage{tikz}
\usepackage{tikz-cd}

\begin{document}

\begin{tikzpicture}[baseline= (a).base]
\node[scale=.5] (a) at (0,0){
\begin{tikzcd}
    A\ar{r}\ar{d}&B\\
    C\ar{r}&D\ar{u}\\
\end{tikzcd}
};
\end{tikzpicture}
\begin{tikzpicture}[baseline= (a).base]
\node[scale=1] (a) at (0,0){
\begin{tikzcd}
    A\ar{r}\ar{d}&B\\
    C\ar{r}&D\ar{u}\\
\end{tikzcd}
};
\end{tikzpicture}
\begin{tikzpicture}[baseline= (a).base]
\node[scale=1.5] (a) at (0,0){
\begin{tikzcd}
    A\ar{r}\ar{d}&B\\
    C\ar{r}&D\ar{u}\\
\end{tikzcd}
};
\end{tikzpicture}
\begin{tikzpicture}[baseline= (a).base]
\node[scale=2] (a) at (0,0){
\begin{tikzcd}
    A\ar{r}\ar{d}&B\\
    C\ar{r}&D\ar{u}\\
\end{tikzcd}
};
\end{tikzpicture}
\end{document}

enter image description here

10

The column seps and row seps are not scaleble in the same way as many other things in TikZ.

You can however install a few matrix scaling keys (that work by installing the scale factor in the row sep and column sep factor).

There are also other ways but I wouldn’t scale the nodes or even use low-level scaling (then \scalebox is better).

Code

\documentclass[varwidth, border={0pt 100pt 0pt 0pt}]{standalone}
\usepackage{tikz-cd}
\makeatletter
\tikzset{
  column sep/.code=\def\pgfmatrixcolumnsep{\pgf@matrix@xscale*(#1)},
  row sep/.code   =\def\pgfmatrixrowsep{\pgf@matrix@yscale*(#1)},
  matrix xscale/.code=%
    \pgfmathsetmacro\pgf@matrix@xscale{\pgf@matrix@xscale*(#1)},
  matrix yscale/.code=%
    \pgfmathsetmacro\pgf@matrix@yscale{\pgf@matrix@yscale*(#1)},
  matrix scale/.style={/tikz/matrix xscale={#1},/tikz/matrix yscale={#1}}}
\def\pgf@matrix@xscale{1}
\def\pgf@matrix@yscale{1}
\makeatother
\begin{document}
Normal:\par
\begin{tikzcd}
    A \ar{r}\ar{d} & B        \\
    C \ar{r}       & D \ar{u}
\end{tikzcd}\bigskip

With \texttt{tikzcd} options (one of \texttt{tiny}, \texttt{small},
  \texttt{scriptsize}, \texttt{normal}, \texttt{large} and \texttt{huge}):\par
\begin{tikzcd}[row sep=large, column sep=small]
    A \ar{r}\ar{d} & B        \\
    C \ar{r}       & D \ar{u}
\end{tikzcd}\bigskip

Sep scaling:\par
\begin{tikzcd}[matrix scale=1.5]
    A \ar{r}\ar{d} & B        \\
    C \ar{r}       & D \ar{u}
\end{tikzcd}\bigskip

Sep scaling, with nodes:\par
\begin{tikzcd}[matrix scale=1.5, transform shape, nodes={scale=1.5}]
    A \ar{r}\ar{d} & B        \\
    C \ar{r}       & D \ar{u}
\end{tikzcd}\bigskip

Everything, including line widths (does not update the bounding box correctly):\par\centering
\begin{tikzcd}[transform canvas={scale=4}]
    A \ar{r}\ar{d} & B        \\
    C \ar{r}       & D \ar{u}
\end{tikzcd}\bigskip
\end{document}

Output

enter image description here

4

Does the \scalebox command work for you? [But to be honest, I have no idea why the ampersand replacement=\& is needed then]

\documentclass{amsart}

\usepackage{tikz}
\usepackage{tikz-cd}

\usetikzlibrary{matrix}

\begin{document}

\begin{tikzpicture}[column sep=1in,row sep=1in]
    \matrix (A) [matrix of math nodes]
    {
        A& B\\
        C& D\\
    };
    \draw[->] (A-1-1) -- (A-1-2);
    \draw[->] (A-1-1) -- (A-2-1);
    \draw[->] (A-2-1) -- (A-2-2);
    \draw[->] (A-2-2) -- (A-1-2);
\end{tikzpicture}

\scalebox{.5}{
    \begin{tikzpicture}[column sep=1in,row sep=1in,ampersand replacement=\&]
        \matrix (A) [matrix of math nodes]{
            A\& B\\
            C\& D\\
        };
        \draw[->] (A-1-1) -- (A-1-2);
        \draw[->] (A-1-1) -- (A-2-1);
        \draw[->] (A-2-1) -- (A-2-2);
        \draw[->] (A-2-2) -- (A-1-2);
    \end{tikzpicture}
}

\end{document}
2
  • 4
    ampersand replacement is needed any time a TikZ matrix is used as argument to a command.
    – egreg
    Commented Oct 15, 2013 at 15:43
  • The \scalebox command seems only to scale the objects, not the arrows...
    – sgmoye
    Commented Oct 15, 2013 at 15:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .