4

I know that one can change the row and column separation in the \matrix command with row sep, respectively column sep. But how do one change the separation for a specific row or column only?

That is; having different spacing between between different rows? Also, how do one do the same for column spacing?

enter image description here

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \matrix[column sep=5mm, row sep=5mm]
    {
        % Row 1
        \node {1:1};&\node {1:2};&\node {1:3};&\node {1:4};;\\
        % Row 2
        \node {2:1};&\node {2:2};&\node {2:3};&\node {2:4};\\
        % Row 3
        \node {3:1};&\node {3:2};&\node {3:3};&\node {3:4};\\
    };
\end{tikzpicture}
\end{document}
2
  • 2
    Please add a MWE, so we could answer better
    – Puck
    Commented Aug 24, 2021 at 17:30
  • @Puck Updated question. Commented Aug 24, 2021 at 17:52

2 Answers 2

5

You can set the separation to zero; then use &[<width>] in the first row for column separation and \\[<width>] for row separation.

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  \matrix[column sep=0mm, row sep=0mm]{
    % Row 1
    \node {1:1}; &[5mm] \node {1:2}; &[10mm] \node {1:3}; &[10mm] \node {1:4}; \\[5mm]
    % Row 2
    \node {2:1}; &      \node {2:2}; &       \node {2:3}; &       \node {2:4}; \\[10mm]
    % Row 3
    \node {3:1}; &      \node {3:2}; &       \node {3:3}; &       \node {3:4}; \\
  };
\end{tikzpicture}

\end{document}

enter image description here

2

ROW SEPARATION

For the row spacing, instead of specifying a matrix-wide row sep, use the optional argument to \\ to accomplish row specific skips.

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \matrix[column sep=5mm]
    {
        % Row 1
        \node {1:1};&\node {1:2};&\node {1:3};&\node {1:4};;\\[5mm]
        % Row 2
        \node {2:1};&\node {2:2};&\node {2:3};&\node {2:4};\\[10mm]
        % Row 3
        \node {3:1};&\node {3:2};&\node {3:3};&\node {3:4};\\
    };
\end{tikzpicture}
\end{document}

enter image description here

Alternately, you can keep a default row sep and specify the deviation from it:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \matrix[column sep=5mm, row sep=5mm]
    {
        % Row 1
        \node {1:1};&\node {1:2};&\node {1:3};&\node {1:4};;\\
        % Row 2
        \node {2:1};&\node {2:2};&\node {2:3};&\node {2:4};\\[5mm]
        % Row 3
        \node {3:1};&\node {3:2};&\node {3:3};&\node {3:4};\\
    };
\end{tikzpicture}
\end{document}

COLUMN SEPARATION

As to the issue of column separation, I know of no easy way to accomplish this. In the particular example provided by the OP, the column gaps are all integer multiples of each other. If that were always the case, one can just add blank columns:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \matrix[column sep=5mm, row sep=5mm]
    {
        % Row 1
        \node {1:1};&\node {1:2};&&\node {1:3};&\node {1:4};;\\
        % Row 2
        \node {2:1};&\node {2:2};&&\node {2:3};&\node {2:4};\\[5mm]
        % Row 3
        \node {3:1};&\node {3:2};&&\node {3:3};&\node {3:4};\\
    };
\end{tikzpicture}
\end{document}

But I presume that is too much to hope for. The best I could do for the general case is provide the \knode macro that has an optional kern built in.

\documentclass{standalone}
\usepackage{tikz}
\newcommand\knode[2][0]{\node{#2\kern#1mm}}
\begin{document}
\begin{tikzpicture}
    \matrix[column sep=5mm, row sep=5mm]
    {
        % Row 1
        \node {1:1};&\knode[5]{1:2};&\node {1:3};&\node {1:4};;\\
        % Row 2
        \node {2:1};&\knode[5]{2:2};&\node {2:3};&\node {2:4};\\[5mm]
        % Row 3
        \node {3:1};&\knode[5]{3:2};&\node {3:3};&\node {3:4};\\
    };
\end{tikzpicture}
\end{document}

enter image description here

2
  • That solved my question about row spacing, thank you. But I was not clear enough about wanting the same for column separation. Could you update your answer with that too? Commented Aug 25, 2021 at 8:19
  • @RobinHellmers Please see updated answer. Commented Aug 25, 2021 at 9:20

You must log in to answer this question.

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