8

This is a follow-up of Is it possible to fill the second column with something automatically?

I would like to (automatically) reach the following result (fill in the second column with a grid):

\documentclass{book}
\usepackage{geometry}
\usepackage{multicol}

\usepackage[most]{tcolorbox}
\tcbuselibrary{breakable, xparse}

\newtcolorbox[auto counter]{mybox}[2][]{%
    breakable,
    frame hidden,
    opacityback=0,
    sharp corners,
    before skip=10pt,
    enhanced,
    left=6pt,
    right=0pt,
    bottom=0pt,
    boxsep=0pt,
    rightrule=0pt,
    pad at break*=0mm,
    borderline west={1.5pt}{0pt}{red},
    fonttitle=\bfseries,
    coltitle=blue,
    title={\thetcbcounter. #2}
    }

\usepackage{mwe}
\begin{document}
Some text in one column \blindtext
\begin{multicols}{2}
\begin{mybox}{My title}
Some text in two columns \blindtext
\end{mybox}
\vfill\null
\columnbreak
\begin{mybox}{My second title}
\begin{tikzpicture}
\draw[green,thin, step=.5] (0,0) grid (7,7);
\end{tikzpicture}
\end{mybox}
\end{multicols}
\newpage
Some other text in one column
\begin{multicols}{2}
\begin{mybox}{My third title}
Some other text in two columns \blindtext[2]
\end{mybox}
\vfill\null
\columnbreak

\begin{mybox}{My fourth title}
\begin{tikzpicture}
\draw[green,thin, step=.5] (0,0) grid (7,15);
\end{tikzpicture}
\end{mybox}
\end{multicols}
\end{document}

enter image description here

I tried this dirty hack but, of course, it doesn't work:

\documentclass{book}
\usepackage{geometry}
\usepackage{multicol}

\usepackage[most]{tcolorbox}
\tcbuselibrary{breakable, xparse}

\newtcolorbox[auto counter]{mybox}[2][]{%
    breakable,
    frame hidden,
    opacityback=0,
    sharp corners,
    before skip=10pt,
    enhanced,
    left=6pt,
    right=0pt,
    bottom=0pt,
    boxsep=0pt,
    rightrule=0pt,
    pad at break*=0mm,
    borderline west={1.5pt}{0pt}{red},
    fonttitle=\bfseries,
    coltitle=blue,
    title={\thetcbcounter. #2}
    }

\newcommand{\squarefill}[2][.5]{\null
    \vskip-\baselineskip
    \leaders
    \hbox to \columnwidth{\hspace{7.5pt}\begin{tikzpicture}   
    \draw[red,line width=1.5pt, overlay](7.27pt,\pgflinewidth) -- (7.27pt,1); \draw[step=#1,green,thin] (.5,\pgflinewidth) grid (#2*#1,#1);
    \end{tikzpicture}}
    \vfill\vskip-\baselineskip
    \null}

\usepackage{mwe}
\begin{document}
Some text in one column \blindtext
\begin{multicols}{2}
\begin{mybox}{My title}
Some text in two columns \blindtext
\end{mybox}
\vfill\null
\columnbreak
\begin{mybox}{My second title}
\end{mybox}
\squarefill{14}
\end{multicols}
\newpage
Some other text in one column
\begin{multicols}{2}
\begin{mybox}{My third title}
Some other text in two columns \blindtext[2]
\end{mybox}
\vfill\null
\columnbreak

\begin{mybox}{My fourth title}
\end{mybox}
\squarefill{14}
\end{multicols}
\end{document}

enter image description here

A solution without tcolorbox or TikZ is also acceptable if it gives the desired result.

4
  • 1
    I've proposed a solution with tcolorbox following your scheme. But if you always want two columns with controlled height, i think it will be easier to use a tcbraster construction wich will avoid to specify equal height group
    – Ignasi
    Jun 29 at 8:36
  • @Ignasi You're right, a tcbraster could be the solution, I'll try
    – CarLaTeX
    Jun 29 at 9:12
  • I've added a tcbitemize version, hope it helps
    – Ignasi
    Jun 29 at 11:57
  • @Ignasi Thank you very much
    – CarLaTeX
    Jun 29 at 14:10

1 Answer 1

7

This is a solution with tcolorbox and equal height group option. All boxes with same equal height group label have same height after two compilations. The right column box can be automatically filled with a grid using the overlay option and the default nodes.

\documentclass{book}
\usepackage{geometry}
\usepackage{multicol}

\usepackage[most]{tcolorbox}
\tcbuselibrary{breakable, xparse}

\tcbset{
    mybox/.style={
    breakable,
    frame hidden,
    opacityback=0,
    sharp corners,
    before skip=10pt,
    enhanced,
    left=6pt,
    right=0pt,
    bottom=0pt,
    boxsep=0pt,
    rightrule=0pt,
    pad at break*=0mm,
    borderline west={1.5pt}{0pt}{red},
    fonttitle=\bfseries,
    coltitle=blue,
    title={\thetcbcounter. #1}
    }
}

\newtcolorbox[auto counter]{mybox}[2][]{%
    mybox=#2, #1
   }

\newtcolorbox[use counter from=mybox]{mygridbox}[2][]{
    mybox=#2, #1, 
    overlay ={
        \draw[green, thin, step=.5] (interior.north west) grid (interior.south east);
    },
}

\usepackage{mwe}
\begin{document}
Some text in one column \blindtext
\begin{multicols}{2}
\begin{mybox}[equal height group=A]{My title}
Some text in two columns \blindtext
\end{mybox}
\vfill\null
\columnbreak
\begin{mygridbox}[equal height group=A]{My second title}
\end{mygridbox}
\end{multicols}
\newpage
Some other text in one column
\begin{multicols}{2}
\begin{mybox}[equal height group=B]{My third title}
Some other text in two columns \blindtext[2]
\end{mybox}
\vfill\null
\columnbreak
\begin{mygridbox}[equal height group=B]{My fourth title}
\end{mygridbox}
\end{multicols}
\end{document}

enter image description here

Update: tcbraster version

Instead of two independent boxes with equal hight group option, this structure can be easily made with a two columns tcbitemize. Following code shows a possible construction. An external counter is used and previous tcolorboxes are converted into tcbset styles to be applied to each tcbitem.

\documentclass{book}
\usepackage{geometry}

\usepackage[most]{tcolorbox}
\tcbuselibrary{breakable, xparse}

\tcbset{
    mybox/.style={
    frame hidden,
    opacityback=0,
    sharp corners,
    before skip=10pt,
    enhanced,
    left=6pt,
    right=0pt,
    bottom=0pt,
    boxsep=0pt,
    rightrule=0pt,
    pad at break*=0mm,
    borderline west={1.5pt}{0pt}{red},
    fonttitle=\bfseries,
    coltitle=blue,
    step=myboxcounter,
    title={\themyboxcounter. #1}
    },
    mygridbox/.style={
        mybox=#1,
        overlay ={%
        \draw[green, thin, step=.5] (interior.north west) grid (interior.south east);}
    }
}

\newcounter{myboxcounter}

\usepackage{mwe}
\begin{document}
Some text in one column \blindtext

\begin{tcbitemize}[raster columns=2, raster equal height, 
]
\tcbitem[mybox=My title]
Some text in two columns \blindtext
\tcbitem[mygridbox=My second title]
\end{tcbitemize}

\newpage
Some other text in one column
\begin{tcbitemize}[raster columns=2, raster equal height=rows, 
]
\tcbitem[mybox=My third title]
Some other text in two columns \blindtext[2]
\tcbitem[mygridbox=My fourth title]
\end{tcbitemize}
\end{document}

You must log in to answer this question.

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