是否可以自动用网格填充第二列?

是否可以自动用网格填充第二列?

这是是否可以自动用某些内容填充第二列?

我希望(自动)达到以下结果(用网格填充第二列):

\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}

在此处输入图片描述

我尝试了这个肮脏的黑客方法,但是,它当然不起作用:

\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}

在此处输入图片描述

tcolorbox如果它能给出所需的结果,那么不使用 TikZ 的解决方案也是可以接受的。

答案1

tcolorbox这是使用和选项的解决方案equal height group。经过两次编译后,所有具有相同标签的框都具有相同的高度。使用选项和默认节点,equal height group右列框可以自动填充网格。overlay

\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}

在此处输入图片描述

更新:tcbraster版本

无需使用equal hight group选项来制作两个独立的框,只需使用两列即可轻松制作此结构tcbitemize。以下代码显示了一种可能的构造。使用外部计数器,并将先前的计数器tcolorboxes转换tcbset为要应用于每个的样式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}

相关内容