如何在字幕周围设置固定、一致且统一的空白

如何在字幕周围设置固定、一致且统一的空白

问题描述

我希望我的表格、图表和清单具有相同的标题上方或下方的空白量。目前,表格、图形和列表的空白量有所不同。

期望的输出/解决方案

我正在寻找一种解决方案,如何为所有这些环境设置相同的间距。我尝试将skip=5pt表格和图形的间距设置为belowcaptionskip=5ptabovecaptionskip=5pt将列表的间距设置为 。但是,由于某些未知原因,对于某些环境(例如列表或长表),此间距较大,而对于图形环境,此间距稍小。下图显示了所需的间距规格:
所需间距规格 我希望间距 A = 间距 C(均等于且大于间距 B)。

梅威瑟:

\documentclass[12pt,openany,twoside]{book}
\raggedbottom
\usepackage[onehalfspacing]{setspace}
\usepackage{array}
\newcolumntype{I}{!{\vrule width 1pt}}
\newlength\savedwidth
\newcommand\whline{\noalign{\global\savedwidth\arrayrulewidth
        \global\arrayrulewidth 1pt}%
    \hline
    \noalign{\global\arrayrulewidth\savedwidth}}
\usepackage[table]{xcolor}
\definecolor{mintbg}{rgb}{.63,.79,.95}

\usepackage{graphicx}
\newcommand\HRule{\noindent\rule{\linewidth}{1.5pt}}
\usepackage{background}
\backgroundsetup{contents={}}


\usepackage{fancyhdr}
\usepackage{hhline}

\usepackage{tabularx}% 

\pagestyle{fancy}   

\usepackage{float}
\usepackage{longtable}
\usepackage{multirow}
\usepackage{caption}
\usepackage[ragged]{sidecap}
\usepackage[font=small,format=hang,skip=5pt,labelfont={bf},textfont=it]{caption}

\usepackage{etoolbox}

\usepackage{regexpatch}
\usepackage{listings}
\makeatletter
\newcommand{\lstlistcodename}{List of Codes}
\newcounter{code}
\lstnewenvironment{code}[1][]{%
    \renewcommand{\lstlistingname}{Code}%
    \renewcommand{\ext@lstlisting}{loc}%
    %\xpatchcmd*{\caption@ORI@lst@MakeCaption}{lol}{lop}{}{}% use this 
     with earlier version caption package
    \setcounter{lstlisting}{\value{code}}
    \lstset{
        basicstyle         = \ttfamily,
        backgroundcolor=\color{mintbg},
        showtabs=false,
        tabsize=2,
        keepspaces=true,
        breaklines=true,
        framerule=.05pt,
        rulecolor=\color{black},
        columns=[l],
        xleftmargin=5pt,
        xrightmargin=0pt,
        caption=#1,
        captionpos=b,
        belowcaptionskip=5pt,
        abovecaptionskip=5pt,#1}}
{\addtocounter{code}{1}}

\newcommand{\lstlistofcode}{\begingroup
    \tocfile{\lstlistcodename}{loc}
    \endgroup}
\makeatother

\usepackage{apptools}

\usepackage{showframe}  

\begin{document} 
    \chapter{ChapterA}
    
    \begin{figure}[H]
        \centering
        \includegraphics[scale=0.5]{example-image-c}
        \caption{This is a sample figure}
        \label{fig:2019-fcas-actuarial-salary-survey-783x556}
    \end{figure}
    
    \begin{table}[H]
        \begin{tabular}{|c|c|>{\columncolor{blue}}c |c|}
            \hline
            \rowcolor{gray}
            &
            \multicolumn{2}{c|}{Details} &
            \\
            \hhline{
                >{\arrayrulecolor{black}}|
                >{\arrayrulecolor{gray}}-
                >{\arrayrulecolor{black}}|
                >{\arrayrulecolor{black}}-
                >{\arrayrulecolor{black}}-
                >{\arrayrulecolor{gray}}-
                >{\arrayrulecolor{black}}|
            }
            \rowcolor{gray}
            \multirow{-2}{*}{Code} &
            OUYYT &
            GSR &
            \multirow{-2}{*}{Kfger} \\
            \hline \hline
            SHEGW &OIUYfghghrhr rgrrgrgr &Odgegetee eeteteet &1 \\
            \hline
        \end{tabular}
        \caption{Dfhfhrh}
    \end{table}
    \section{Synopsis}
    \begin{longtable}{|p{1.57cm}|p{11cm}|}
        \hline
        \rowcolor{gray}
        \bfseries Code&\bfseries Synopsis\\ \hline \hline
        \endfirsthead
        \hline
        \rowcolor{gray} \bfseries Course Code&\bfseries Synopsis\\ 
        \hline \hline
        \endhead
        \hline \multicolumn{2}{r}{\emph{Continued on next page}}
        \endfoot
        \hline
        \endlastfoot
        \rowcolor{mintbg}   ABC & Preferred Probability, Probability 
        Distributions, Common discrete and continuous distributions, 
        Introduction to bivariate probability distributions, 
        Approximations  \\ \hline
        \caption{Summary}
    \end{longtable}
    
    \section{Special keyboard characters}
    THdiie eeieieiei ejejejeje.
    
    \begin{code}[caption = {Sample code}]
        %% Code sections are highlighted.
        % System command are supported...
        !gzip sample.m
        % ... as is line continuation.
        A = [1, 2, 3,... % (mimicking the ouput is good)
        4, 5, 6]
        fid = fopen('testFile.text', 'w')
        for i=1:10
        fprintf(fid,'%6.2f \n', i);
        end
        x=1; %% this is just a comment, though
        % Context-sensitive keywords get highlighted
        p = properties(mydate); %(here, properties is a)
        x = linspace(0,1,101);
        y = x(end:-1:1)
        % ... even in nonsensical code.
        ]end()()(((end end)end ))))end (function end
        %{
            block comments are supported
            %} even
        runaway block comments
        are
    \end{code}
    
\end{document}

相关内容