使用漂亮的盒子/tcolorbox创建页面布局

使用漂亮的盒子/tcolorbox创建页面布局

来自这个主题:灵感来自 Indesign 的精美盒子。现在,我想创建带有不同框(如附件图像)的页面布局。如果可能,请使用 tcbposter 或其他解决方案。谢谢 此框代码: 在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage[most]{tcolorbox}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage[english]{babel}
\usepackage{MnSymbol,wasysym}
\usepackage{tikzsymbols} 
\usepackage{caption}
\usepackage{adjustbox}
\input{insbox}
\makeatletter
\tcbset{
    myhbox/.style 2 args={%
        enhanced, 
        breakable,
        colback=white,
        colframe=blue!30!black,
        attach boxed title to top left={yshift*=-\tcboxedtitleheight}, 
        title={#2},
        boxed title size=title,
        boxed title style={%
            sharp corners, 
            rounded corners=northwest, 
            colback=tcbcol@frame, 
            boxrule=0pt,
        },
        underlay boxed title={%
            \path[fill=tcbcol@frame] (title.south west)--(title.south east) 
                to[out=0, in=180] ([xshift=5mm]title.east)--
                (title.center-|frame.east)
                [rounded corners=\kvtcb@arc] |- 
                (frame.north) -| cycle; 
        },
        #1
    },
    myvbox/.style 2 args={%
        enhanced, 
        colback=white,
        colframe=blue!30!black,
        left=8mm,
        overlay={
            \node[rotate=90, anchor=north west, inner sep=2mm, text=white] (title@aux) at (frame.south west) {#2};
            \path[fill=tcbcol@frame] ([email protected] west)--([email protected] east) 
                to[out=90, in=270] ([yshift=5mm][email protected])--
                ([email protected]|-frame.north)
                [rounded corners=\kvtcb@arc] -| 
                (frame.west) |- ([email protected])[sharp corners] -- cycle;   
            \node[rotate=90, inner sep=2mm, text=white] at (title@aux) {#2};
        },
        #1
    },  
}   

\makeatother

\newtcolorbox{myhbox}[2][]{%
    myhbox={#1}{#2}
}

\newtcolorbox{myvbox}[2][]{%
    myvbox={#1}{#2}
}
\begin{document}



\begin{myhbox}[colframe=blue!80!black,height=3cm,width =7cm]{AAA}{

def
}
\end{myhbox}

\begin{myhbox}[colframe=blue!80!black,height=3cm,width =7cm]
{BBB }{
abc
}
\end{myhbox}


  \begin{myvbox}[colframe=red!80!black,height=6cm,width =4cm,before=\adjustbox{valign=t}\bgroup,after=\egroup]{CCC}


    { 
   abcdef
    }% 

\end{myvbox}
\begin{myvbox}[colframe=red!80!black,height=6cm,width =4cm,before=\adjustbox{valign=t}\bgroup,after=\egroup]{DDD}


    { 
   abcdef
    }% 

\end{myvbox}

\begin{tcbposter}[
poster = {
%       showframe, 
        columns = 2,
        rows = 2,
        height = .5\textheight, 
        width = .5\textwidth, 
        spacing=3mm},
    boxes = {colback=red}
    ]
    \begin{posterbox}{column=1, row=1}[colframe=red!80!black,height=6cm,width =4cm]{ABCD}
   \end{posterbox}
  \end{tcbposter}%
\end{document}

答案1

BVOT 似乎需要具有特定尺寸的盒子:

例如:A4 纸宽度尺寸 = 29.7 厘米,我想要总计(所有列框 = 27 厘米)并且框 CCC 宽度 = 15 厘米,AAA 宽度 = 5 厘米,BBB 宽度 = 7 厘米。

在这种情况下,使用 会更容易tcbposter。Atcbposter是列和行的初始规则分布,其中放置框,并参考列、行和其他框。

由于所需框的宽度不成比例,我使用了只有两列的框。左框将与左框对齐,右框将与右框对齐。第一行的中间框将从左边框tcbposter放置。xshifted

建议的尺寸不允许列之间有空间,因此我减少了左框和第一列的右框,以便在列之间留出一些空间。

\documentclass[a4paper, landscape]{article}
\usepackage{lmodern}
\usepackage[most]{tcolorbox}
\usepackage[textwidth=27cm]{geometry}

\makeatletter
\tcbset{
    myhbox/.style 2 args={%
        enhanced, 
        breakable,
        colback=white,
        colframe=blue!30!black,
        attach boxed title to top left={yshift*=-\tcboxedtitleheight}, 
        title={#2},
        boxed title size=title,
        boxed title style={%
            sharp corners, 
            rounded corners=northwest, 
            colback=tcbcolframe, 
            boxrule=0pt,
        },
        underlay boxed title={%
            \path[fill=tcbcolframe] (title.south west)--(title.south east) 
                to[out=0, in=180] ([xshift=5mm]title.east)--
                (title.center-|frame.east)
                [rounded corners=\kvtcb@arc] |- 
                (frame.north) -| cycle; 
        },
        #1
    },
    myvbox/.style 2 args={%
        enhanced, 
        colback=white,
        colframe=blue!30!black,
        left=8mm,
        overlay={
            \node[rotate=90, anchor=north west, inner sep=2mm, text=white] (title@aux) at (frame.south west) {#2};
            \path[fill=tcbcolframe] ([email protected] west)--([email protected] east) 
                to[out=90, in=270] ([yshift=5mm][email protected])--
                ([email protected]|-frame.north)
                [rounded corners=\kvtcb@arc] -| 
                (frame.west) |- ([email protected])[sharp corners] -- cycle;   
            \node[rotate=90, inner sep=2mm, text=white] at (title@aux) {#2};
        },
        #1
    },  
}   
\makeatother

\begin{document}
\thispagestyle{empty}
\noindent%
\begin{tcbposter}[
    poster = {columns=2, rows=2, width=\textwidth, height=\textheight}]
\posterbox[width=15cm-\tcbpostercolspacing, myvbox={colframe=red!80!black}{CCC}]{column=1, row=1, rowspan=2}{CCC}
\posterbox[width=5cm, myhbox={}{AAA}]{column=1, row=1, xshift=15cm}{AAA}
\posterbox[width=7cm-\tcbpostercolspacing, myhbox={}{BBB}]{column*=2, row=1}{BBB}
\posterbox[width=12cm, myhbox={}{DDD}]{column*=2, row=2}{DDD}

\end{tcbposter}
\end{document}

在此处输入图片描述

笔记先前的代码已更新,以兼容 tcolorbox v4.20。如果您使用的是先前版本,请将颜色形式重命名tcbcol...为旧形式 tcbcol@...

答案2

这种分布也可以通过 实现tcbraster。这里有一些示例。更多信息请参见tcolorbox文档

\documentclass[a4paper]{article}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}

\makeatletter
\tcbset{
    myhbox/.style 2 args={%
        enhanced, 
        breakable,
        colback=white,
        colframe=blue!30!black,
        attach boxed title to top left={yshift*=-\tcboxedtitleheight}, 
        title={#2},
        boxed title size=title,
        boxed title style={%
            sharp corners, 
            rounded corners=northwest, 
            colback=tcbcolframe, 
            boxrule=0pt,
        },
        underlay boxed title={%
            \path[fill=tcbcolframe] (title.south west)--(title.south east) 
                to[out=0, in=180] ([xshift=5mm]title.east)--
                (title.center-|frame.east)
                [rounded corners=\kvtcb@arc] |- 
                (frame.north) -| cycle; 
        },
        #1
    },
    myvbox/.style 2 args={%
        enhanced, 
        colback=white,
        colframe=blue!30!black,
        left=8mm,
        overlay={
            \node[rotate=90, anchor=north west, inner sep=2mm, text=white] (title@aux) at (frame.south west) {#2};
            \path[fill=tcbcolframe] ([email protected] west)--([email protected] east) 
                to[out=90, in=270] ([yshift=5mm][email protected])--
                ([email protected]|-frame.north)
                [rounded corners=\kvtcb@arc] -| 
                (frame.west) |- ([email protected])[sharp corners] -- cycle;   
            \node[rotate=90, inner sep=2mm, text=white] at (title@aux) {#2};
        },
        #1
    },  
}   
\makeatother

\newtcolorbox{myhbox}[2][]{%
    myhbox={#1}{#2}
}

\newtcolorbox{myvbox}[2][]{%
    myvbox={#1}{#2}
}

\begin{document}

\begin{tcbitemize}[%
    raster columns=2, 
    raster rows=2, 
    raster equal height=rows,
    ]
    \tcbitem[blankest]
        \begin{tcbitemize}[raster columns=1]
            \tcbitem[myhbox={}{AAA}]    First box with horizontal title
            \tcbitem[myhbox={}{AAA}]    Second box with horizontal title
        \end{tcbitemize}
    \tcbitem[myvbox={colframe=red!70!black}{CCC}]Box with vertical title
\end{tcbitemize}
\vspace{1cm}

\begin{tcbitemize}[%
    raster columns=5, 
    raster rows=2, 
    raster equal height=rows,
    ]
    \tcbitem[raster multirow=2, raster multicolumn=3, blankest]
        \begin{tcbitemize}[raster columns=1]
            \tcbitem[myhbox={}{AAA}]    First box with horizontal title
            \tcbitem[myhbox={}{AAA}]    Second box with horizontal title
        \end{tcbitemize}
    \tcbitem[raster multicolumn=2, myvbox={colframe=red!70!black}{CCC}]Box with vertical title
\end{tcbitemize}
\vspace{1cm}

\begin{tcbitemize}[%
    raster columns=3, 
    raster rows=2, 
    raster equal height=rows,
    ]
    \tcbitem[raster multirow=2, myvbox={colframe=red!70!black}{CCC}]Box with vertical title
    \tcbitem[raster multicolumn=2, blankest]
        \begin{tcbitemize}[raster columns=2]
            \tcbitem[myhbox={}{AAA}]    First box with horizontal title
            \tcbitem[myhbox={}{BBB}]    Second box with horizontal title
            \tcbitem[raster multicolumn=2, myhbox={}{BBB}] Double horizontal box
        \end{tcbitemize}
\end{tcbitemize}

\end{document}

在此处输入图片描述

笔记先前的代码已更新,以兼容 tcolorbox v4.20。如果您使用的是先前版本,请将颜色形式重命名tcbcol...为旧形式 tcbcol@...

相关内容