多色和文字背景顏色

多色和文字背景顏色

我正在搜尋建立一個multicol文件的方法,其中每列都有背景顏色,如下圖所示。彩色區域(紅色矩形)應填滿背景顏色。由於文件有很多列(範例中為 4 列,但實際上有 10 列),因此將文字拆分為小頁或類似內容並不是我最喜歡的選擇。

在此輸入影像描述

答案1

如果我們假設您正在使用不平衡列並希望有列邊框全部文件的頁面,然後您可以使用以下命令將它們作為覆蓋的一部分插入背景中eso-pic(或其他一些包;有多個選項):

在此輸入影像描述

\documentclass{article}

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

\usepackage{xcolor,eso-pic}
\newlength{\columnwidths}
\AtBeginDocument{\setlength{\columnwidths}{\dimexpr.25\textwidth-.75\columnsep}}
\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{\dimexpr\columnsep-2\fboxsep-2\fboxrule}%
    \fcolorbox{red}{white}{\rule{\columnwidths}{0pt}\rule{0pt}{\textheight}}% Second column
    \hspace{\dimexpr\columnsep-2\fboxsep-2\fboxrule}%
    \fcolorbox{red}{white}{\rule{\columnwidths}{0pt}\rule{0pt}{\textheight}}% Third column
    \hspace{\dimexpr\columnsep-2\fboxsep-2\fboxrule}%
    \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}

相關內容