为列添加背景颜色

为列添加背景颜色

我正在使用一篇两列文章,我想只为两列设置背景颜色,而不是整个页面。我该怎么做?我正在使用以下模板。我还想为摘要部分设置单独的背景颜色。在此处输入图片描述

代码:从此链接

\documentclass[twoside]{article}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\linespread{1.05} % Palatino needs more space between lines
\usepackage{microtype}
\usepackage[hmarginratio=1:1,top=32mm,columnsep=20pt]{geometry}
\usepackage[font=it]{caption}
\usepackage{paralist}
\usepackage{multicol}
\usepackage{lettrine}
\usepackage{lipsum}


\usepackage{abstract}
    \renewcommand{\abstractnamefont}{\normalfont\bfseries}
\renewcommand{\abstracttextfont}{\normalfont\small\itshape}

\usepackage{titlesec}
    \renewcommand\thesection{\Roman{section}}
    \titleformat{\section}[block]{\large\scshape\centering}{\thesection.}{1em}{}

\usepackage{fancyhdr}
    \pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\fancyhead[C]{Journal paper template $\bullet$ April 2012 $\bullet$ Vol. XXI, No. 1}
\fancyfoot[RO,LE]{\thepage}

\usepackage{hyperref}
\title{\vspace{-15mm}%
    \fontsize{24pt}{10pt}\selectfont
\textbf{Long Titles Look More Impressive Than Short Ones}
}   

\author{%
\large
\textsc{Jonathan S. Doe}\thanks{Template by \href{http://www.howtotex.com}{howtoTeX.com}} \\[2mm]
\normalsize University of Technology, Delft \\
\normalsize \href{mailto:[email protected]}{[email protected]}
\vspace{-5mm}
}
\date{}

\begin{document}
\maketitle
\thispagestyle{fancy}

\begin{abstract}
\noindent \lipsum[1]
\end{abstract}


\begin{multicols}{2} 
\lipsum[1]

\section{Section title example}
\lipsum[1-2]

\section{One more section}
\lipsum[3-5]

\end{multicols}

\end{document}

答案1

结合答案关联以及周围的摘要colorbox

\documentclass[twoside]{article}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\linespread{1.05} % Palatino needs more space between lines
\usepackage{microtype}
\usepackage[hmarginratio=1:1,top=32mm,columnsep=20pt]{geometry}
\usepackage[font=it]{caption}
\usepackage{paralist}
\usepackage{multicol}
\usepackage{lettrine}
\usepackage{lipsum}
\usepackage{xcolor}

\usepackage{abstract}
    \renewcommand{\abstractnamefont}{\normalfont\bfseries}
\renewcommand{\abstracttextfont}{\normalfont\small\itshape}

\usepackage{titlesec}
    \renewcommand\thesection{\Roman{section}}
    \titleformat{\section}[block]{\large\scshape\centering}{\thesection.}{1em}{}

\usepackage{fancyhdr}
    \pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\fancyhead[C]{Journal paper template $\bullet$ April 2012 $\bullet$ Vol. XXI, No. 1}
\fancyfoot[RO,LE]{\thepage}

\usepackage{hyperref}
\title{\vspace{-15mm}%
    \fontsize{24pt}{10pt}\selectfont
\textbf{Long Titles Look More Impressive Than Short Ones}
}

\author{%
\large
\textsc{Jonathan S. Doe}\thanks{Template by \href{http://www.howtotex.com}{howtoTeX.com}} \\[2mm]
\normalsize University of Technology, Delft \\
\normalsize \href{mailto:[email protected]}{[email protected]}
\vspace{-5mm}
}
\date{}

\makeatletter
\let\old@page@sofar\page@sofar
\let\old@box\box
\let\old@rlap\rlap
\def\page@sofar{%
\let\box\colorcolumn
\def\rlap{\let\box\old@box\old@rlap}%
\old@page@sofar
}
\def\colorcolumn#1{%
       \kern\dimexpr-\fboxrule-\fboxsep\relax
        {\let\box\old@box\fcolorbox{orange!30}{orange!30}{\box#1\llap{\phantom p}}}%
        \kern\dimexpr-\fboxrule-\fboxsep\relax
}
\makeatother

\begin{document}
\maketitle
\thispagestyle{fancy}

\begin{abstract}
\hspace{-0.7cm}\colorbox{yellow!50}{
\parbox{\linewidth}{
\noindent \lipsum[1]
}
}
\end{abstract}

\begin{multicols}{2} 
\lipsum[1]

\section{Section title example}
\lipsum[1-2]

\section{One more section}
\lipsum[3-5]

\end{multicols}

\end{document}

请注意,mdframed解决方案会因某种溢出而失败。 编译输出

相关内容