我正在制作一个双列文档,但我需要一个带有背景颜色的单列摘要,为此我正在使用 tcolorbox,如果摘要的内容太长,那么摘要内容将移动到下一页,如果我不使用“tcolorbox”,那么它就可以工作了。还有其他方法吗?
\documentclass[twocolumn]{article}
\usepackage{geometry,graphicx,xcolor,enumitem,amsmath,caption}
\definecolor{Cgreen}{RGB}{41,106,48}%LIGHT
\usepackage[most]{tcolorbox}
%\usepackage{long2}
\makeatletter
%%
%% This is file `long2.sty'.
%%
%% Author: Tomas "tohecz" Hejda <[email protected]>
%%
%% Licenced under LaTeX-Project Public License version 1.3 or newer.
%%
\NeedsTeXFormat{LaTeX2e}[1995/06/01]
\ProvidesPackage{long2}[2012/08/19 v0.1 long2: breakable one-column preamble in a two-column document]
\newlength\longtwo@top
\newlength\longtwo@bottom
\newsavebox\longtwo@box
\def\longtwo@repeat{%
\longtwo@column[{\@twocolumnfalse
\ifdim\ht\longtwo@box>1.00\textheight%1
\begingroup
\vbadness10000
\setbox0\vsplit\longtwo@box to 1.00\textheight%1
\setbox1\vbox{\unvbox\longtwo@box}
\global\setbox\longtwo@box\vbox{\unvbox1}
\setbox2\vbox to \textheight{%
\unvbox0
}
\ht2=0.9\textheight
\box2
\endgroup
\else
\ifdim\ht\longtwo@box>0.84\textheight
\global\let\longtwo@repeat\clearpage
\else
\global\let\longtwo@repeat\relax
\fi
\unvbox\longtwo@box
\vspace{15pt plus 15pt}
\fi
}]%
\longtwo@repeat
}
\long\def\longtwo@[#1]{%
\begingroup
\let\longtwo@column\twocolumn
\let\longtwo@mkttl\maketitle
\def\maketitle{
\begingroup
\let\newpage\relax
\longtwo@mkttl
\endgroup
}
\longtwo@column[{\@twocolumnfalse
\global\setbox\longtwo@box\vbox{#1}%
\ifdim\ht\longtwo@box>\textheight
\begingroup
\vbadness10000
\setbox0\vsplit\longtwo@box to 1.00\textheight%1
\setbox1\vbox{\unvbox\longtwo@box}%
\global\setbox\longtwo@box\vbox{\unvbox1}%
\setbox2\vbox to \textheight{%
\unvbox0
}
\ht2=0.9\textheight
\box2
\endgroup
\else
\ifdim\ht\longtwo@box>0.87\textheight
\global\let\longtwo@repeat\clearpage
\else
\global\let\longtwo@repeat\relax
\fi
\unvbox\longtwo@box
\fi
}]%
\longtwo@repeat
\endgroup
}
\def\longtwocolumn{\@ifnextchar[\longtwo@\twocolumn}
%\endinput
%%
%% End of file `long2.sty'.
%%
\makeatother
\usepackage{lipsum}
\parskip0pt plus 8pt
\title{My title}
\author{My the first}
\begin{document}
\longtwocolumn[{\maketitle
\begin{tcolorbox}[enhanced jigsaw,
breakable,
size=title,
sharp corners,
rounded corners=northeast,
rounded corners=northwest,
colback=Cgreen!25!white,
colframe=Cgreen,
fonttitle=\bfseries,
titlerule=1mm,
titlerule style=black,
title={\center Key Messages
},
pad at break=2mm,
break at=-\baselineskip/0pt,
height fixed for=middle]
\begin{abstract}
\lipsum[1-18]
\end{abstract}
\end{tcolorbox}
%\lipsum[9-15]
}]
\lipsum[16-25]
\end{document}
答案1
问题似乎是,tcolorbox
放置在单列环境中的 ,又嵌入在双列上下文中,仍然表现得像在双列环境中一样。因此,您需要准确地告诉它在哪里中断。您可以使用选项来执行此操作,break at
并明确说明第一页上的框的大小。
例如,break at=15cm/0pt
意味着可破坏框的第一部分(即标题后面的部分)的尺寸应为 15 厘米(这似乎是标题下方空间的大小),后面的框应尽可能大。(您的代码中已经有类似的东西了。)
遗憾的是,如果您决定将标题弄大一些(通过添加更多行),则需要调整这个明确的陈述。
以下方法似乎有效(尽管似乎存在较小的对齐问题):
\documentclass[twocolumn]{article}
\usepackage{geometry,graphicx,xcolor,enumitem,amsmath,caption}
\definecolor{Cgreen}{RGB}{41,106,48}%LIGHT
\usepackage[most]{tcolorbox}
\begin{filecontents}{long2.sty}
%%
%% This is file `long2.sty'.
%%
%% Author: Tomas "tohecz" Hejda <[email protected]>
%%
%% Licenced under LaTeX-Project Public License version 1.3 or newer.
%%
\NeedsTeXFormat{LaTeX2e}[1995/06/01]
\ProvidesPackage{long2}[2012/08/19 v0.1 long2: breakable one-column preamble in a two-column document]
\newlength\longtwo@top
\newlength\longtwo@bottom
\newsavebox\longtwo@box
\def\longtwo@repeat{%
\longtwo@column[{\@twocolumnfalse
\ifdim\ht\longtwo@box>1.00\textheight%1
\begingroup
\vbadness10000
\setbox0\vsplit\longtwo@box to 1.00\textheight%1
\setbox1\vbox{\unvbox\longtwo@box}
\global\setbox\longtwo@box\vbox{\unvbox1}
\setbox2\vbox to \textheight{%
\unvbox0
}
\ht2=0.9\textheight
\box2
\endgroup
\else
\ifdim\ht\longtwo@box>0.84\textheight
\global\let\longtwo@repeat\clearpage
\else
\global\let\longtwo@repeat\relax
\fi
\unvbox\longtwo@box
\vspace{15pt plus 15pt}
\fi
}]%
\longtwo@repeat
}
\long\def\longtwo@[#1]{%
\begingroup
\let\longtwo@column\twocolumn
\let\longtwo@mkttl\maketitle
\def\maketitle{
\begingroup
\let\newpage\relax
\longtwo@mkttl
\endgroup
}
\longtwo@column[{\@twocolumnfalse
\global\setbox\longtwo@box\vbox{#1}%
\ifdim\ht\longtwo@box>\textheight
\begingroup
\vbadness10000
\setbox0\vsplit\longtwo@box to 1.00\textheight%1
\setbox1\vbox{\unvbox\longtwo@box}%
\global\setbox\longtwo@box\vbox{\unvbox1}%
\setbox2\vbox to \textheight{%
\unvbox0
}
\ht2=0.9\textheight
\box2
\endgroup
\else
\ifdim\ht\longtwo@box>0.87\textheight
\global\let\longtwo@repeat\clearpage
\else
\global\let\longtwo@repeat\relax
\fi
\unvbox\longtwo@box
\fi
}]%
\longtwo@repeat
\endgroup
}
\def\longtwocolumn{\@ifnextchar[\longtwo@\twocolumn}
%\endinput
%%
%% End of file `long2.sty'.
%%
\end{filecontents}
\usepackage{long2}
\parskip0pt plus 8pt
\usepackage{lipsum}
\title{My title}
\author{My the first}
\begin{document}
\longtwocolumn[{%
\maketitle
\begin{tcolorbox}[enhanced jigsaw,
breakable,
break at=15cm/0pt, % <-- !
size=title,
sharp corners,
rounded corners=northeast,
rounded corners=northwest,
colback=Cgreen!25!white,
colframe=Cgreen,
fonttitle=\bfseries,
titlerule=1mm,
titlerule style=black,
title={\center Key Messages},
pad at break=2mm]
\lipsum[1-16]
\end{tcolorbox}
\lipsum[5-10]
}]
\lipsum[16-25]
\end{document}
不过,你也应该考虑使用multicol
包,将正文换成双栏环境。这样可能会更简单一些。
\documentclass{article}
\usepackage{geometry,graphicx,xcolor,enumitem,amsmath,caption}
\definecolor{Cgreen}{RGB}{41,106,48}%LIGHT
\usepackage[most]{tcolorbox}
\usepackage{multicol}
\parskip0pt plus 8pt
\usepackage{lipsum}
\title{My title}
\author{My the first}
\begin{document}
\maketitle
\begin{tcolorbox}[enhanced jigsaw,
breakable,
size=title,
sharp corners,
rounded corners=northeast,
rounded corners=northwest,
colback=Cgreen!25!white,
colframe=Cgreen,
fonttitle=\bfseries,
titlerule=1mm,
titlerule style=black,
title={\center Key Messages},
pad at break=2mm]
\lipsum[1-6]
\end{tcolorbox}
\lipsum[5-10]
\begin{multicols}{2}%
\lipsum[16-25]
\end{multicols}
\end{document}