TransWikia.com

How to arrange color box vertically parallel to each other in a color box?

TeX - LaTeX Asked by Muhammad Ali Baig on August 15, 2021

I have tried the following code. I want color box "C" should be vertically parallel to color box "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 = Hugeslshapetextbf,
   center title, 
   title     = #2,
   #1}

newtcolorbox{BlueBox}[2][]{%
   enhanced,
   colback   = blue!5!white,
   colframe  = blue!65!black, 
   arc       = 4mm, 
   outer arc = 1mm, 
   fonttitle = Largeslshapetextbf,
   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}

enter image description here

3 Answers

with raster valign=center

enter image description here

with raster valign=top

enter image description here

MWE

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 = Hugeslshapetextbf,
        center title, 
        title     = #2,
        #1}
    
    newtcolorbox{BlueBox}[2][]{%
        enhanced,
        colback   = blue!5!white,
        colframe  = blue!65!black, 
        arc       = 4mm, 
        outer arc = 1mm, 
        fonttitle = Largeslshapetextbf,
        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}

Correct answer by js bibra on August 15, 2021

There is no need for tcbraster in this case. The problem comes from the empty lines between boxes and hfill. An empty line in LaTeX means to start a newparagraph, therefore nobeforeafter option and hfill have no effect. Just delete these empty lines or comment out, you get boxes A and B one beside the other.

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 = Hugeslshapetextbf,
   center title, 
   title     = #2,
   #1}

newtcolorbox{BlueBox}[2][]{%
   enhanced,
   colback   = blue!5!white,
   colframe  = blue!65!black, 
   arc       = 4mm, 
   outer arc = 1mm, 
   fonttitle = Largeslshapetextbf,
   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}

enter image description here

Update: After my answer I've seen that OP wants box C beside box B and I did it wrong. The best solution could be to declare box C just after box A and box B after them. Another solution could be to use a multi column environment inside the tcolorbox.

Answered by Ignasi on August 15, 2021

I have tried the following codes. But I have an issue the width of the boxes.

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 = Hugeslshapetextbf,
   center title, 
   title     = #2,
   #1}

newtcolorbox{BlueBox}[2][]{%
   enhanced,
   colback   = blue!5!white,
   colframe  = blue!65!black, 
   arc       = 4mm, 
   outer arc = 1mm, 
   fonttitle = Largeslshapetextbf,
   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}

enter image description here

Answered by Muhammad Ali Baig on August 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP