0

I'm using tcolorbox/tcbposter in order to draw some figures because it's actually pretty practical to use this grid (I usually first write the image in standalone mode, and then include it in some documents using the \input{} with the standalone package activated).

However, I can't find an easy way to add more columns without changing the size of the other columns (like I can't see an option to set the width of a column). For example, let's imagine I draw this:

enter image description here

Now, I'd like to add one more column on the right. If I just increase the number of columns and add my node, the result is not good because it changes the length of the other columns: enter image description here

Similarly, if I keep 3 columns but change the coverage right=2cm option to increase the bounding box (in order to make the arrow appear, I don't have better methods), then I also change the size of the columns:

enter image description here

Any idea how I could fix the width of the columns in order to be able to expand the coverage of the number of columns without changing my drawing?

Thanks!

MWE:

\documentclass{standalone}
\usepackage[many,poster]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{fit,backgrounds}
\begin{document}
\begin{tcbposter}[
  poster = {
    height=5cm,
    spacing=10mm,
    % Can't add a new column without breaking the "Here I am :)"
    % on two lines.
    %% Good result but on 3 columns:
    % columns=3,
    % Breals the length of the other columns:
    columns=4,
    rows=3,
  },
  coverage={
    % Can't set this number to 2 without breaking the "Here I am :)"
    % on two lines. So 'X' is invisible.
    left=2cm, 
    % right=0cm
  }
  ]
  \posterbox{name=A,column=2,row=1,rowspan=2}{Here I am :)}
  \posterbox{name=C,column=3,row=2}{$C$}
  \posterbox{name=D,column=1,row=3}{$D$}
  % I would like now to add a node.
  \posterbox{name=E,column=4,row=1}{$E$}
  \draw [->] (TCBPOSTER@C) -- (TCBPOSTER@A.east |- TCBPOSTER@C);
  \draw [->] (TCBPOSTER@A) -- (TCBPOSTER@D);
  % And draw outside without changing the size
  \draw [->] (TCBPOSTER@D.west) -- ++(-1.5cm,0mm) node[above] {X};
\end{tcbposter}%
\end{document}
2
  • Decide how wide are your columns, how many columns and intercolumn space and fix poster's width (\tcbposterset{poster={width=20cm,height=15cm}}). By default, posterwidth is \linewidth (I don't know how is it fixed in standalone) and columns width is decided dividing this width by the number of columns. – Ignasi Apr 15 '20 at 14:41
  • By the way, why do you want to use tcbposter to draw something which seems to be easily drawn with TikZ? – Ignasi Apr 15 '20 at 14:42
3

tcolorbox uses \linewidth as the default width for all boxes, tcpbosters included. You can change this width with width option in posterset command.

But this width is used to fix columns width in tcbposters. When you change column number from 3 to 4, columns are narrower because more columns have to be fitted into the box.

If you want to keep a certain column width when you increase columns, you have to change tcbposter width.

Following code shows an example. The first supposes 4 columns 3cm width and 10mm spacing between them plus a left margin with 2cm. The total width is fixed in coverage options. And on the second one, I've added a new column which means a 4cm wider width. This way columns keep their size.

I'm sure you will be able to find an automatic way of doing it.

\documentclass{standalone}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{fit,backgrounds}
\standaloneenv{tcbposter}
\begin{document}
\begin{tcbposter}[
  poster = {
    height=5cm,
    spacing=10mm,
    columns=4,
    rows=3,
  },
  coverage={
     %width=columns*columnwidth+(columns-1)*spacing+coverage-margins
     width=17cm,
    left=2cm, 
    right=0cm
  }
  ]
  \posterbox{name=A,column=2,row=1,rowspan=2}{Here I am :)}
  \posterbox{name=C,column=3,row=2}{$C$}
  \posterbox{name=D,column=1,row=3}{$D$}
  % I would like now to add a node.
  \posterbox{name=E,column=4,row=1}{$E$}
  \draw [->] (TCBPOSTER@C) -- (TCBPOSTER@A.east |- TCBPOSTER@C);
  \draw [->] (TCBPOSTER@A) -- (TCBPOSTER@D);
  % And draw outside without changing the size
  \draw [->] (TCBPOSTER@D.west) -- ++(-1.5cm,0mm) node[above] {X};
\end{tcbposter}%

\begin{tcbposter}[
  poster = {
    height=5cm,
    spacing=10mm,
    columns=5,
    rows=3,
  },
  coverage={
     %width=columns*columnwidth+(columns-1)*spacing+coverage-margins
     width=21cm, 
    left=2cm, 
    right=0cm
  }
  ]
  \posterbox{name=A,column=2,row=1,rowspan=2}{Here I am :)}
  \posterbox{name=C,column=3,row=2}{$C$}
  \posterbox{name=D,column=1,row=3}{$D$}
  % I would like now to add a node.
  \posterbox{name=E,column=4,row=1}{$E$}
  \posterbox{name=E,column=5,row=2}{$F$}
  \draw [->] (TCBPOSTER@C) -- (TCBPOSTER@A.east |- TCBPOSTER@C);
  \draw [->] (TCBPOSTER@A) -- (TCBPOSTER@D);
  % And draw outside without changing the size
  \draw [->] (TCBPOSTER@D.west) -- ++(-1.5cm,0mm) node[above] {X};
\end{tcbposter}%
\end{document}

enter image description here

It seems that you want to use tcposter because it defines a grid for boxes allocation. But something similar can be obtained with a TikZ matrix. Following code shows an example. The matrix defines a regular structure (like tcbposter) and over this structure you can place nodes. Some of them can be drawn as matrix components, and some other can be drawn using the grid provided by the matrix.

\documentclass[tikz, border=2mm]{standalone}

\usetikzlibrary{fit, matrix}

\begin{document}
\begin{tikzpicture}[
    mynodes/.style={rounded corners, minimum width=3cm, minimum height=1cm, anchor=center},
    phantom/.style={mynodes, draw=gray!30, fill=none},
    drawn/.style={phantom, draw=black, fill=gray!30},
    mygrid/.style={
        matrix of nodes, nodes in empty cells,
        nodes={phantom},
        column sep=7mm, row sep=7mm},
    myfit/.style={drawn, inner sep=0pt, fit=#1}
    ]

    \matrix (a) [mygrid]
    {&&&|[drawn]|E\\ 
    &&|[drawn]|C& \\ 
    |[drawn]|D&&&\\};
    \node[myfit={(a-1-2) (a-2-2)}] (b) {Here I am :)};
    \draw[->] (a-2-3)--(a-2-3-|a-2-2.east);
    \draw[->] (b)--(a-3-1);
    \draw[->] (a-3-1.west)--++(180:2cm);
\end{tikzpicture}
\end{document}

enter image description here

5
  • Sorry for the time I spent to answer, and thanks a lot for the detailled answer! I think I'll go back to pure tikz at some point, thanks! Just one question, concerning the formula, what is +coverage-margins? For example left is supposed to be a margin, or a coverage? – tobiasBora Apr 21 '20 at 18:14
  • And also (sorry if needed I can create another question), but is it possible to specify the number of columns of the tikz matrix directly, i.e. without writting lot's of &&&&&? – tobiasBora Apr 21 '20 at 18:19
  • @tobiasBora coverage-margins means left and right margins that you want to add to the tcbposter. In your case is 2cm+0cm. – Ignasi Apr 22 '20 at 6:35
  • @tobiasBora How to construct a tikz matrix with some loops has been discussed several times here. But you should investigate. This could be a starting point: tex.stackexchange.com/q/47595/1952 – Ignasi Apr 22 '20 at 6:41
  • Oh, I thought it was "coverage minus margin". Thanks! – tobiasBora Apr 22 '20 at 17:53

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.