带有阴影背景颜色的列表在底部添加块

带有阴影背景颜色的列表在底部添加块

目前我不知道为什么阴影框会在我的列表底部添加这个间距:

在此处输入图片描述

我不确定阴影框是否在标题后添加了这个间距,或者列表是否只是在标题后添加了这个额外的间距。这是我为此列表编写的 latex 代码:

\begin{shaded}
  \begin{lstlisting}[caption=Definition of a relation object., label=list:relation-object, language=JavaScript]
var UserProjectRelation = relation
  .from(User)
  .to(Project)
  .via("member");
  \end{lstlisting}
\end{shaded}

这是我对列表的设置:

\lstdefinelanguage{JavaScript}{
  keywords={typeof, new, true, false, catch, function, return, null, catch, switch, var, let, const, if, in, while, do, else, case, break, from},
  ndkeywords={class, export, boolean, throw, implements, import, this, string, number, boolean},
  sensitive=false,
  comment=[l]{//},
  morecomment=[s]{/*}{*/},
  morestring=[b]',
  morestring=[b]",
  inputencoding=utf8
}

\lstset{
   language=JavaScript,
   numbers=left,
   captionpos=b
}
\definecolor{shadecolor}{named}{sbase03}

\DeclareCaptionFormat{captionFormat}{%
  \color{white}{\ttfamily#1#2#3}
} 
\captionsetup[lstlisting]{format=captionFormat}

编辑:

这是我使用的软件包和文档类型:

\documentclass[%
fontsize=\myfontsize,%% size of the main text
paper=\mypapersize,  %% paper format
parskip=\myparskip,  %% vertical space between paragraphs (instead of indenting first par-line)
DIV=calc,            %% calculates a good DIV value for type area; 66 characters/line is great
headinclude=true,    %% is header part of margin space or part of page content?
footinclude=false,   %% is footer part of margin space or part of page content?
open=right,          %% "right" or "left": start new chapter on right or left page
appendixprefix=true, %% adds appendix prefix; only for book-classes with \backmatter
bibliography=totoc,  %% adds the bibliography to table of contents (without number)
draft=\mydraft,      %% if true: included graphics are omitted and black boxes
                     %%          mark overfull boxes in margin space
BCOR=\myBCOR,        %% binding correction (depends on how you bind
                     %% the resulting printout.
\mylaterality        %% oneside: document is not printed on left and right sides, only right side
                     %% twoside: document is printed on left and right sides
]{scrbook}  %% article class of KOMA: "scrartcl", "scrreprt", or "scrbook".
            %% CAUTION: If documentclass will be changed, *many* other things
            %%          change as well like heading structure, ...

\usepackage[utf8]{inputenc} %% UTF8 as input characters

\usepackage[backend=biber, %% using "biber" to compile references (instead of "biblatex")
style=\mybiblatexstyle, %% see biblatex documentation
%style=alphabetic, %% see biblatex documentation
%dashed=\mybiblatexdashed, %% do *not* replace recurring reference authors with a dash
backref=\mybiblatexbackref, %% create backlings from references to citations
natbib=true, %% offering natbib-compatible commands
hyperref=true, %% using hyperref-package references
]{biblatex}  %% remove, if using BibTeX instead of biblatex

\addbibresource{\mybiblatexfile} %% remove, if using BibTeX instead of biblatex
\usepackage[pdftex]{graphicx}
\usepackage{pifont}
\usepackage{ifthen}
\usepackage{xspace}
\usepackage[usenames,dvipsnames,x11names,rgb,html]{xcolor}
\usepackage[normalem]{ulem}
\usepackage{framed}
\usepackage{eso-pic}
\usepackage{enumitem}
\usepackage{units}

\usepackage{listings}
\usepackage{float}
\usepackage{solarized-dark}
\usepackage{framed}
\usepackage{subcaption}
\usepackage{etoolbox}


\begin{document}

...

\end{document}

答案1

我在@Cragfelt 的帮助下自己解决了这个问题!我整理了一个最小的工作示例,并检查了我的自定义日光化样式。

样式定义中有这样一行:

belowcaptionskip=1\baselineskip,

我将其改为 0,现在它可以工作了,唯一的例外是我添加了一半以\baselineskip\relax将标题置于底部空间的中间:

最后结果

\documentclass[%
  fontsize=12pt,
  paper=A4,
  parskip=half,
  DIV=calc,
  headinclude=true,
  footinclude=false,
  open=right,
  appendixprefix=true,
  bibliography=totoc,
  draft=false,
  BCOR=0mm,
  twoside
]{scrbook}

\usepackage[utf8]{inputenc}

\usepackage[pdftex]{graphicx}
\usepackage{pifont}
\usepackage{ifthen}
\usepackage{xspace}
\usepackage[usenames,dvipsnames,x11names,rgb,html]{xcolor}
\usepackage[normalem]{ulem}
\usepackage{framed}
\usepackage{eso-pic}
\usepackage{enumitem}
\usepackage{units}

\usepackage{listings}
\usepackage{float}
\usepackage{solarized-dark}
\usepackage{framed}
\usepackage{subcaption}
\usepackage{etoolbox}

\lstdefinelanguage{JavaScript}{
  keywords={typeof, new, true, false, catch, function, return, null, catch, switch, var, let, const, if, in, while, do, else, case, break, from},
  ndkeywords={class, export, boolean, throw, implements, import, this, string, number, boolean},
  sensitive=false,
  comment=[l]{//},
  morecomment=[s]{/*}{*/},
  morestring=[b]',
  morestring=[b]",
  inputencoding=utf8
}

\lstset{
  language=JavaScript,
  numbers=left,
  captionpos=b
}
\definecolor{sbase03}{HTML}{002B36}
\definecolor{shadecolor}{named}{sbase03}

\DeclareCaptionFormat{captionFormat}{%
  \color{white}{\ttfamily#1#2#3%
  \mbox{}\vspace{-\dimexpr\topsep+0.5\baselineskip\relax}}
} 
\captionsetup[lstlisting]{format=captionFormat, font={color=white}, labelfont=bf}

\begin{document}

\begin{shaded}
  \begin{lstlisting}[caption=Definition of a relation object., label=list:relation-object, language=JavaScript]
var UserProjectRelation = relation
  .from(User)
  .to(Project)
  .via("member");
  \end{lstlisting}
\end{shaded}

\end{document}

答案2

也许这个解决方法可行

在此处输入图片描述

我无法使用提供的代码编译您的作品以显示如图所示的确切列表框,而我不得不模仿图像中的颜色。由于某些我无法找到的功能,规则都没有出现。但令人高兴的是,您需要做的一点补充与这些功能无关,而是与标题后的额外空白有关。正如我的评论所说,您需要在标题格式的定义中添加\mbox{}\vspace{-\dimexpr\topsep+\baselineskip\relax}after ( )。这将缩短框底部的额外空间。#1#2#3\DeclareCaptionFormat

\DeclareCaptionFormat{captionFormat}{%
\color{white}{\ttfamily#1#2#3%
\mbox{}\vspace{-\dimexpr\topsep+\baselineskip\relax}}
} 
\captionsetup[lstlisting]{format=captionFormat}

相关内容