TransWikia.com

Multicol and text background color

TeX - LaTeX Asked by highsciguy on June 20, 2021

I am searching means to create a multicol document in which each column has a background color like illustrated below. The colored areas (red rectangles) should be filled with the background color. Since the document has many columns (4 in the example, but 10 in reality) splitting the text in minipages or similar is not my favored option.

enter image description here

One Answer

If we assume that you are using unbalanced columns and want to have the column borders on all of the pages of your document, then you can insert them in the background as part of an overlay using eso-pic (or some other package; there are multiple options):

enter image description here

documentclass{article}

usepackage{lipsum,multicol}
usepackage[paper=a3paper,margin=1in]{geometry}

usepackage{xcolor,eso-pic}
newlength{columnwidths}
AtBeginDocument{setlength{columnwidths}{dimexpr.25textwidth-.75columnsep}}
AddToShipoutPictureBG{% Add to *all* pages in the BackGround
  AtTextLowerLeft{%
    hspace{dimexpr-fboxsep-fboxrule}%
    fcolorbox{red}{white}{rule{columnwidths}{0pt}rule{0pt}{textheight}}% First column
    hspace{dimexprcolumnsep-2fboxsep-2fboxrule}%
    fcolorbox{red}{white}{rule{columnwidths}{0pt}rule{0pt}{textheight}}% Second column
    hspace{dimexprcolumnsep-2fboxsep-2fboxrule}%
    fcolorbox{red}{white}{rule{columnwidths}{0pt}rule{0pt}{textheight}}% Third column
    hspace{dimexprcolumnsep-2fboxsep-2fboxrule}%
    fcolorbox{red}{white}{rule{columnwidths}{0pt}rule{0pt}{textheight}}% Fourth column
  }%
}

begin{document}

sloppy% Just for this example
begin{multicols*}{4}
lipsum[1-50]
lipsum[1-9]
end{multicols*}

end{document}

Answered by Werner on June 20, 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