考虑以下生成列表的代码:
% ---------------------------------------------------------------------------- %
% Preamble
\documentclass[12pt]{article}
% ---------------------------------------------------------------------------- %
% Packages
\usepackage{calc}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{multicol}
\usepackage{printlen}
\usepackage[most]{tcolorbox}
% ---------------------------------------------------------------------------- %
% Length
\newlength{\evenlength}
\setlength{\evenlength}{0pt}
\newlength{\oddlength}
\setlength{\oddlength}{10pt}
% ---------------------------------------------------------------------------- %
% Listing
\newtcblisting{lstbox}[4][\normalsize]{
code = {},
enhanced,
listing only,
top = 0pt,
%%%%%%
% I want bottom to be equal to:
% - \evenlength if the listing has an even number of lines
% - \oddlength if the listing has an even number of lines
bottom = 0pt,
%%%%%%
left = 0pt,
right = 0pt,
arc = 0pt,
outer arc = 0pt,
boxsep = 0pt,
titlerule = 0pt,
colback = red,
colframe = black,
boxrule = 2pt,
title = {\centering{\fontfamily{cmtt}\selectfont#2\strut}},
listing options = {
language = C++,
framesep = 0pt,
rulesep = 0pt,
aboveskip = 0pt,
belowskip = 0pt,
backgroundcolor = \color{lightgray},
basicstyle = \fontfamily{cmtt}\selectfont#1,
#3,
},
#4,
}
% ---------------------------------------------------------------------------- %
% Document
\pagestyle{empty}
\begin{document}
\begin{lstbox}[\small]{title}{}{}
1
2
\end{lstbox}
\begin{lstbox}[\small]{title}{}{}
1
2
3
\end{lstbox}
\begin{lstbox}[\small]{title}{}{}
1
2
3
4
\end{lstbox}
\end{document}
% ---------------------------------------------------------------------------- %
有没有办法让tcolorbox
bottom
选项等于
\evenlength
当列表有偶数行时\oddlength
当列表有奇数行时