我想要有带有不同类型标题的不同列表,请考虑我有以下内容:
\documentclass{article}
\usepackage{listings}
\usepackage{color}
\usepackage{caption}
\definecolor{listinggray}{gray}{0.98}
\definecolor{lbcolor}{rgb}{0.98,0.98,0.98}
\lstset{
basicstyle=\footnotesize\ttfamily,
numberstyle=\tiny,
numberbychapter=true,
numbersep=5pt,
float=tp,
tabsize=2,
xleftmargin=5pt,
framexleftmargin=5pt,
extendedchars=true,
breaklines=true,
frame=tb,
showspaces=false,
showtabs=false,
backgroundcolor=\color{lbcolor},
rulecolor=\color[rgb]{0.78,0.78,0.78},
framerule=0.5pt,
showstringspaces=false,
keywordstyle=\color[rgb]{1.0,0,0}
}
\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox[cmyk]{0.43, 0.35, 0.35,0.01}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{#1#2#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white, singlelinecheck=false, margin=0pt, font={bf,footnotesize}}
\lstnewenvironment{code}[1][]%
{\noindent\minipage{\linewidth}
\lstset{#1}
}
{\endminipage}
\lstnewenvironment{tip}[1][caption=Tip]%
{
\noindent\minipage{\linewidth}
\def\lstlistingautorefname{Tip}
\lstset{#1,keywordstyle=\color{black},numberbychapter=false,basicstyle=\footnotesize\ttfamily\color{black}\bfseries, backgroundcolor=\color{white},frame=none,captionpos=bc }
}
{\endminipage}
\begin{document}
\begin{code}[caption=Test]
Code test..
\end{code}
....Look, just because I don't be givin' no man a foot massage don't make it right for Marsellus....
\begin{tip}
A tip!
\end{tip}
{\begin{figure}%
This is what I want!
\caption{}%
\label{}%
\end{figure}
\end{document}
这将生成以下内容:
基本上,我希望所有列表的标题都在左上角,但对于环境,tip
我希望它位于底部中央,因为它看第三个例子,但标题应该说“提示 1”。
这可能吗?如果可以,怎么做?
答案1
该软件包提供了通过和caption
定义和执行自己的选项集的可能性。这样,您可以为和的标题定义不同的外观。\captionsetup[<name>]{...}
\captionsetup{options=<name>}
code
tip
(不幸的是,该密钥options
没有很好地记录下来,目前它仅在caption
包文档的字母参考中列出。)
为了tip
独立标记和计数,需要为 定义自己的计数器tip
。解决方案的这一部分取自https://stackoverflow.com/questions/3900847/latex-listings-different-counters-for-different-listing-environments
\documentclass{article}
\usepackage{listings}
\usepackage{color}
\usepackage{caption}
\definecolor{listinggray}{gray}{0.98}
\definecolor{lbcolor}{rgb}{0.98,0.98,0.98}
\lstset{
% ...
float=tp,
% ...
}
\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox[cmyk]{0.43, 0.35, 0.35,0.01}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{#1#2#3}}}
\captionsetup[code]{format=listing,labelfont=white,textfont=white, singlelinecheck=false, margin=0pt, font={bf,footnotesize}}
\lstnewenvironment{code}[1][]%
{\noindent\minipage{\linewidth}%
\lstset{#1}%
\captionsetup{options=code}% execute options set with \captionsetup[code]{...}
}
{\endminipage}
\makeatletter
\newcounter{tip}
\lstnewenvironment{tip}[1][]%
{%
\noindent\minipage{\linewidth}%
\def\lstlistingname{Tip}%
\def\lstlistingautorefname{Tip}%
\let\c@lstlisting=\c@tip
\let\thelstlisting=\thetip
\lstset{#1,keywordstyle=\color{black},numberbychapter=false,basicstyle=\footnotesize\ttfamily\color{black}\bfseries, backgroundcolor=\color{white},frame=none,captionpos=bc}%
\captionsetup{options=tip}% execute options set with \captionsetup[tip]{...}
}
{\endminipage}
\makeatother
\begin{document}
\begin{code}[caption=Test]
Code test..
\end{code}
....Look, just because I don't be givin' no man a foot massage don't make it right for Marsellus....
\begin{tip}[caption=Test]
A tip!
\end{tip}
\end{document}