关于如何减少标题底线和代码之间的垂直空间,有什么建议吗?
提前致谢, Humberto
这是我当前的代码
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multicol}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{caption}
\DeclareCaptionFormat{myformat}{#1#2#3\hrulefill}
\captionsetup{format=myformat}
\captionsetup[lstlisting]{position=bottom,format=myformat}
\lstdefinelanguage{Elixir}{
alsodigit = {:},
keywords = {if, and, or, do, end, receive, def, match, defmodule, use, fn, when},
backgroundcolor=\color{white},
rulecolor = \color{black},
backgroundcolor = \color{white},
basicstyle=\scriptsize\ttfamily,
showtabs = false,
numbers = left,
numberstyle = \scriptsize,
stepnumber = 1,
showstringspaces = false,
breaklines=true,
comment=[l]{\#},
numbersep=-8pt,
basicstyle=\small\ttfamily,
columns=fullflexible,
extendedchars=true,
frame=none,
}
\begin{document}
\begin{center}
\captionof{lstlisting}{My caption}
\begin{multicols}{2}
\begin{lstlisting}[label=lst:elixir1, language=Elixir]
def loop({ts_a, ts_b}) do
state =
receive do
{:msg_a, ts} ->
{ts, ts_b}
{:msg_b, ts} ->
{ts_a, ts}
{:msg_c, ts} ->
if ts_b > ts_a do
# reaction code
end
{0,0}
end
loop(state)
end
\end{lstlisting}
\end{multicols}
\end{center}
\end{document}
答案1
更新:
首先,因为是在环境\captionof
之前使用,所以设置比较合适。lstlisting
\captionsetup[lstlisting]{position=top, ...}
这样,\hrulefill
双列lstlisting
环境之间的垂直空间就来自:
- 跳过以下标题,即
\abovecaptionskip
(默认值为 10pt),以及 - 跳过上述
multicols
环境,即\multicolsep
(默认值为 12pt 加 4pt 减 3pt)。
通过设置
\DeclareCaptionFormat{myformat}{#1#2#3\hrulefill}
\captionsetup[lstlisting]{position=top, skip=-\multicolsep, format=myformat}
skip
您还可以在包的帮助下将粘合表达式传递给选项calc
,以便(自由地)调整跳过:
\usepackage{calc}
\DeclareCaptionFormat{myformat}{#1#2#3\hrulefill}
\captionsetup[lstlisting]{position=top, skip=-\multicolsep+5pt, format=myformat}
原始答案:
这可能不是一个理想的解决方案,但似乎有效:
\DeclareCaptionFormat{myformat}{#1#2#3\hrulefill\vspace{-\medskipamount}}