2

I'm trying to draw a fit node in the background using the poster library of tcolorbox. Unfortunately it does not work as expected, because the drawing is above. I tried to play with layers, but it does not work.

enter image description here

\documentclass[tikz]{standalone}
\usepackage[many,poster]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{fit}

\begin{document}
\begin{tcbposter}[
  poster = {
    height=5cm,
    spacing=10mm,
    columns=3,
    rows=3,
  },
  coverage={
    overlay={
      % This does not work because there is a strange
      % shift...
      % \node[fit=(TCBPOSTER@A)(TCBPOSTER@B),inner sep=3mm,draw=red,fill=red!50!white,opacity=.7] {};
    }
  }
  ]
  \posterbox{name=A,column=2,row=1}{$A$}
  \posterbox{name=B,column=2,row=2}{$B$}
  \posterbox{name=C,column=3,row=2}{$C$}
  \draw [->] (TCBPOSTER@A) -- (TCBPOSTER@B);
  \draw [->] (TCBPOSTER@C) -- (TCBPOSTER@B);
  \node[fit=(TCBPOSTER@A)(TCBPOSTER@B),inner sep=3mm,draw=red,fill=red!50!white,opacity=.7] {};
  % Bonus if you can make this arrow appear completely without
  % manually tweaking coverage/right=2cm.
  \draw[->] (TCBPOSTER@C.east) -- ++(2cm,0cm);
\end{tcbposter}%
\end{document}
2

Answering the main question is easy: add the fit node on the background layer.

\documentclass{standalone}
\usepackage[many,poster]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{fit,backgrounds}
\begin{document}
\begin{tcbposter}[
  poster = {
    height=5cm,
    spacing=10mm,
    columns=3,
    rows=3,
  },
  coverage={
    overlay={
      % This does not work because there is a strange
      % shift...
      %\node[fit=(TCBPOSTER@A)(TCBPOSTER@B),inner sep=3mm,draw=red,fill=red!50!white,opacity=.7] {};
    }
  }
  ]
  \posterbox{name=A,column=2,row=1}{$A$}
  \posterbox{name=B,column=2,row=2}{$B$}
  \posterbox{name=C,column=3,row=2}{$C$}
  \draw [->] (TCBPOSTER@A) -- (TCBPOSTER@B);
  \draw [->] (TCBPOSTER@C) -- (TCBPOSTER@B);
  \begin{scope}[on background layer]
   \node[fit=(TCBPOSTER@A)(TCBPOSTER@B),inner
  sep=3mm,draw=red,fill=red!50!white,opacity=.7] {};
  \end{scope}
  % Bonus if you can make this arrow appear completely without
  % manually tweaking coverage/right=2cm.
  \draw[->] (TCBPOSTER@C.east) -- ++(2cm,0cm);
\end{tcbposter}%
\end{document}

enter image description here

I do not understand the bonus question. How should the arrow fit if you keep the size the same?

3
  • Oh, I'm so stupid, I was trying to use the layers without the scope environment, thinking that it would also work... Thanks a lot, sorry for the stupid question. For the bonus, I mean in standalone environment the border "cut" the arrow (while usually in tikz drawing the page fits to the whole drawing). I know it's possible to manually change the size using coverage={right=2cm}, but I'd like to avoid this manual tricks. – tobiasBora Apr 14 '20 at 21:09
  • @tobiasBora I am not a tcolorbox expert but as far as I understand usually, unlike tikzpictures, tcolorbox does not dynamically adjust the bounding box. In this case, if it did, how would that work? Should only the third column get wider? Probably not, this does not look good. Should all column widths grow? Possibly, but then you lose the nice feature of being able to produce a box of a fixed size. However, I cannot exclude that there are keys for that. – user194703 Apr 14 '20 at 21:29
  • Oh, I would not touch the width of the borders (it would change the drawing otherwise), just the bounding box of the whole drawing to make sure all the external elements are drawn, like in tikz. But nevermind, it's another question, thanks! – tobiasBora Apr 15 '20 at 6:43

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.