如何在彩盒内将彩盒垂直平行排列?

如何在彩盒内将彩盒垂直平行排列?

我尝试了以下代码。我希望颜色框“C”应垂直平行于颜色框“A”。

\documentclass\[border=10pt\]{standalone}
\usepackage\[most\]{tcolorbox}

\begin{document}

\newtcolorbox{GreenBox}\[2\]\[\]{%
   enhanced,
   colback   = green!5!white,
   colframe  = green!75!black, 
   arc       = 4mm, 
   outer arc = 1mm, 
   fonttitle = \Huge\slshape\textbf,
   center title, 
   title     = #2,
   #1}

\newtcolorbox{BlueBox}\[2\]\[\]{%
   enhanced,
   colback   = blue!5!white,
   colframe  = blue!65!black, 
   arc       = 4mm, 
   outer arc = 1mm, 
   fonttitle = \Large\slshape\textbf,
   center title, 
   title     = #2,
   #1}
 

\begin{GreenBox}\[width=11cm, remember as=box1, nobeforeafter\]{ABC}

  \begin{BlueBox}\[width=5cm, remember as=box11, nobeforeafter\]{A}
  Some Text here.
  \end{BlueBox}
  
  \hfill
  
  \begin{BlueBox}\[width=5cm, remember as=box12, nobeforeafter\]{B}
  \end{BlueBox}
  
  \hfill
  
  \begin{BlueBox}\[width=5cm, remember as=box13, nobeforeafter\]{C}
  \end{BlueBox}

  
\end{GreenBox}


\end{document}

在此处输入图片描述

答案1

raster valign=center

在此处输入图片描述

raster valign=top

在此处输入图片描述

平均能量损失

\documentclass{standalone}
\usepackage[most]{tcolorbox}

\begin{document}
    
    \newtcolorbox{GreenBox}[2][]{%
        enhanced,
        colback   = green!5!white,
        colframe  = green!75!black, 
        arc       = 4mm, 
        outer arc = 1mm, 
        fonttitle = \Huge\slshape\textbf,
        center title, 
        title     = #2,
        #1}
    
    \newtcolorbox{BlueBox}[2][]{%
        enhanced,
        colback   = blue!5!white,
        colframe  = blue!65!black, 
        arc       = 4mm, 
        outer arc = 1mm, 
        fonttitle = \Large\slshape\textbf,
        center title, 
        title     = #2,
        #1}
    
    
    \begin{GreenBox}[width=11cm, remember as=box1, nobeforeafter,]{ABC}
        \begin{tcbraster}[raster columns=2, raster valign=top]%<------------added
            
        \begin{BlueBox}[width=5cm, remember as=box11, nobeforeafter]{A}
            Some Text here.
        \end{BlueBox}
        \begin{BlueBox}[width=5cm, remember as=box12, nobeforeafter]{B}
        \end{BlueBox}
        \begin{BlueBox}[width=5cm, remember as=box13, nobeforeafter]{C}
        \end{BlueBox}
        \end{tcbraster}
    \end{GreenBox}
    
    
\end{document}

答案2

在这种情况下,不需要tcbraster。问题出在框和之间的空行\hfill。LaTeX 中的空行表示开始一个新段落,因此nobeforeafter选项和\hfill无效。只需删除这些空行或注释掉,您就会得到一个并排的框 A 和 B。

\documentclass[border=10pt]{standalone}
\usepackage[most]{tcolorbox}

\begin{document}

\newtcolorbox{GreenBox}[2][]{%
   enhanced,
   colback   = green!5!white,
   colframe  = green!75!black, 
   arc       = 4mm, 
   outer arc = 1mm, 
   fonttitle = \Huge\slshape\textbf,
   center title, 
   title     = #2,
   #1}

\newtcolorbox{BlueBox}[2][]{%
   enhanced,
   colback   = blue!5!white,
   colframe  = blue!65!black, 
   arc       = 4mm, 
   outer arc = 1mm, 
   fonttitle = \Large\slshape\textbf,
   center title, 
   title     = #2,
   #1}
 

\begin{GreenBox}[width=11cm, remember as=box1, nobeforeafter]{ABC}

  \begin{BlueBox}[width=5cm, remember as=box11, nobeforeafter]{A}
  Some Text here.
  \end{BlueBox}
  %
  \hfill
  %
  \begin{BlueBox}[width=5cm, remember as=box12, nobeforeafter]{B}
  \end{BlueBox}
    
  \begin{BlueBox}[width=5cm, remember as=box13, nobeforeafter]{C}
  \end{BlueBox}
\end{GreenBox}


\end{document}

在此处输入图片描述

更新:在我回答之后,我发现 OP 想要将框 C 放在框 B 旁边,而我做错了。最好的解决方案可能是将框 C 声明在框 A 之后,将框 B 声明在框 A 之后。另一个解决方案可能是在 tcolorbox 中使用多列环境。

答案3

我尝试了以下代码。但我遇到了框宽度问题。

\documentclass[border=10pt]{standalone}

\usepackage{enumitem}
\setlist[itemize]{leftmargin=*, itemsep = 0em}
\usepackage[none]{hyphenat}

\usepackage{tikz}
\usetikzlibrary{matrix, shapes, arrows, positioning}

\usepackage[most]{tcolorbox}


\begin{document}

\newtcolorbox{GreenBox}[2][]{%
   enhanced,
   colback   = green!5!white,
   colframe  = green!75!black, 
   arc       = 4mm, 
   outer arc = 1mm, 
   fonttitle = \Huge\slshape\textbf,
   center title, 
   title     = #2,
   #1}

\newtcolorbox{BlueBox}[2][]{%
   enhanced,
   colback   = blue!5!white,
   colframe  = blue!65!black, 
   arc       = 4mm, 
   outer arc = 1mm, 
   fonttitle = \Large\slshape\textbf,
   center title, 
   title     = #2,
   #1}

 \begin{tcbraster}[raster columns=3, raster valign=center] 

\begin{GreenBox}[width=10cm, remember as=box1, nobeforeafter]{Objectives 1}

 \begin{tcbraster}[raster columns=1, raster valign=center] 
  
  \begin{BlueBox}[width=10cm, remember as=box14, nobeforeafter]{Objective 1.1}
  Some text here.
    \end{BlueBox}
  \end{tcbraster}
  \end{GreenBox}
  \begin{GreenBox}[width=5cm, remember as=box2, nobeforeafter]{Objective 2}
Some text here.
\end{GreenBox}
  \begin{GreenBox}[width=5cm, remember as=box3, nobeforeafter]{Objective 3}
Some text here
\end{GreenBox}
\end{tcbraster}

\end{document}

在此处输入图片描述

相关内容