我想采用以下代码,并使行交替使用背景颜色,没有使用表格,因为这样会破坏两列,而不使用多列,因为这样会破坏浮动。这可能吗?
\documentclass[10pt,twocolumn]{article}
\usepackage[english]{babel}
\usepackage{scrextend}
\newcounter{foonum}
\newcommand{\roll}{
\stepcounter{foonum}
\arabic{foonum}
}
\begin{document}
\begin{labeling}{\textbf{roll}}
\item [\textbf{roll}] \textbf{item}
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\item [\roll] Item
\end{labeling}
\end{document}
编辑:使用@Pouya 的答案,这就是我的想法。但我需要找到一种方法来减少或消除项目之间的巨大差距。
\documentclass[10pt,twocolumn]{article}
\usepackage[english]{babel}
\usepackage{scrextend}
\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{framed}
\colorlet{shadecolor}{blue!20}
\usepackage{adjustbox}
\newcounter{foonum}
\newcommand{\roll}{
\stepcounter{foonum}
\arabic{foonum}
}
\newcommand{\AltItem}[1]{%
\ifodd \value{foonum}
\begin{mdframed}[hidealllines=true,
backgroundcolor=blue!20,
innerleftmargin=1.5pt,
innerrightmargin=10pt,
leftmargin=-18pt,
innertopmargin=-6pt,
innerbottommargin=6pt]
\item [\roll] \hangindent=15pt #1%
\end{mdframed}
\else
\begin{mdframed}[hidealllines=true,
backgroundcolor=red!20,
innerleftmargin=1.5pt,
innerrightmargin=10pt,
leftmargin=-18pt,
innertopmargin=-6pt,
innerbottommargin=6pt]
\item [\roll] \hangindent=15pt #1%
\end{mdframed}
\fi
}
\begin{document}
\begin{labeling}{\textbf{roll}}
\item [\textbf{roll}] \textbf{item}
\AltItem {This is a longer sentence. This is a longer sentence. This is a longer sentence. This is a longer sentence. This is a longer sentence. This is a longer sentence.}
\AltItem {This is a longer sentence. This is a longer sentence. This is a longer sentence. This is a longer sentence. This is a longer sentence. This is a longer sentence.}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\end{labeling}
\end{document}
答案1
以下解决方案并不优雅,还有很大的改进空间。它使用计数器,foonum
并检查值是否为奇数,然后根据奇数设置背景颜色。
有两点需要注意:1. 就目前情况而言,你应该更新item 命令和 2. 突出显示本身需要调整。对于后者,请参阅这全面的答案,自己尝试一下。我的答案只是一个起点...
\documentclass[10pt,twocolumn]{article}
\usepackage[english]{babel}
\usepackage{scrextend}
\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{framed}
\colorlet{shadecolor}{blue!20}
\usepackage{adjustbox}
\newcounter{foonum}
\newcommand{\roll}{
\stepcounter{foonum}
\arabic{foonum}
}
\newcommand{\AltItem}[1]{%
\ifodd \value{foonum}
%% test:
% \textcolor{red}{\item [\roll] #1}%
%% see https://tex.stackexchange.com/a/59342/22492
%% -----------1--------------
% \begin{mdframed}[hidealllines=true,backgroundcolor=blue!20,innerleftmargin=3pt,innerrightmargin=3pt]%,leftmargin=-20pt,rightmargin=-3pt,skipbelow=10pt,skipabove=10pt
% \item [\roll] #1%
% \end{mdframed}
%% -----------2--------------
\begin{shaded}
\item [\roll] #1%
\end{shaded}
%% -----------3--------------
% \noindent\adjustbox{bgcolor=blue!20,minipage=[t]{\linewidth}}{\item [\roll] #1}
\else
\item [\roll] #1%
\fi
}
\begin{document}
\begin{labeling}{\textbf{roll}}
\item [\textbf{roll}] \textbf{item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\AltItem {Item}
\end{labeling}
\end{document}