TransWikia.com

tcolorbox: How to enforce inner sep at tcolorbox raster?

TeX - LaTeX Asked on January 10, 2021

I set left=5pt, right=5pt, top=5pt, bottom=5pt for the inner sep of a tcolorbox raster.

He tries to set the boxes height on the highest box – that’s ok and wanted.

He also tries to set the raster across the entire text width – that’s ok too – but he substitutes the inner xsep in the box / column with the content "X".
How can I force in that box that the settings left=5pt, right=5pt are set?

enter image description here

% arara: pdflatex
% arara: pdflatex

documentclass{article}
usepackage[showframe=true, margin=2cm]{geometry}
usepackage[most]{tcolorbox}

usepackage{lipsum}
begin{document}
begin{tcbitemize}[%
raster equal height=rows, 
raster columns=3,
halign=left, valign=top, 
% This is the point =========================
left=5pt, right=5pt, top=5pt, bottom=5pt,
% ===================================
]
tcbitem lipsum[66]
tcbitem[colframe=red, halign=center, valign=center] Huge X
tcbitem lipsum[63]
end{tcbitemize}
end{document}

One Answer

By default a tcbraster equally divides its total width (linewidth by default) between its columns. This is the reason for your wider than expected central box.

You can force the width for a particular box with raster force size=false and some add to width on a particular box. But in this case you have to manually compute all widths in order to distribute the available space.

documentclass{article}
usepackage[showframe=true, margin=2cm]{geometry}
usepackage[most]{tcolorbox}

usepackage{lipsum}
begin{document}
begin{tcbitemize}[%
raster equal height=rows, 
raster columns=3,
halign=left, valign=top, 
% This is the point =========================
left=5pt, right=5pt, top=5pt, bottom=5pt,
% ===================================
raster force size=false
]
tcbitem lipsum[66]
tcbitem[colframe=red, halign=center, valign=center] Huge X
tcbitem lipsum[65]


tcbitem lipsum[66]
tcbitem[colframe=red, halign=center, valign=center, add to width = -3cm] Huge X
tcbitem lipsum[65]

tcbitem[add to width=1.5cm] lipsum[66]
tcbitem[colframe=red, halign=center, valign=center, add to width = -3cm] Huge X
tcbitem[add to width=1.5cm] lipsum[65]

end{tcbitemize}
end{document}

enter image description here

Another solution to have different width columns could be the raster multicolumn option. In this case you define a default large number of columns (9 in following example) but group in three visible boxes where first and third has a width equivalent to four initial boxes.

documentclass{article}
usepackage[showframe=true, margin=2cm]{geometry}
usepackage[most]{tcolorbox}

usepackage{lipsum}
begin{document}
begin{tcbitemize}[%
raster equal height=rows, 
raster columns=9,
halign=left, valign=top, 
% This is the point =========================
left=5pt, right=5pt, top=5pt, bottom=5pt,
% ===================================
%raster force size=false
]
tcbitem[raster multicolumn=4] lipsum[66]
tcbitem[colframe=red, halign=center, valign=center] Huge X
tcbitem[raster multicolumn=4] lipsum[65]


tcbitem[raster multicolumn=4] lipsum[66]
tcbitem[colframe=red, halign=center, valign=center] Huge X
tcbitem[raster multicolumn=4] lipsum[65]

tcbitem[raster multicolumn=4] lipsum[66]
tcbitem[colframe=red, halign=center, valign=center] Huge X
tcbitem[raster multicolumn=4] lipsum[65]

end{tcbitemize}
end{document}

enter image description here

In any case, width tcbraster you cannot expect that boxes adapt the width to its contents (and respect inner margins) because their size is defined by the raster width and the columns number and not by their contents.

Correct answer by Ignasi on January 10, 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