不同风格的字幕

不同风格的字幕

我正在写一份文档,其中有不同类型的图表,如表格和列表。为了得到我想要的标题,我在序言中写了以下内容:

\usepackage[font=small, labelfont=bf, justification=raggedright, format=hang]{caption}

\captionsetup[table]{position=below}
\captionsetup[figure]{position=below}

现在我发现列表和表格上的标题与图片中的不同

不同类型的字幕

该指令不应该\usepackage[...]{caption}改变文档中所有标题的样式吗?

最小示例:

\documentclass[
    12pt, % font size
    ngerman, % german umlaute and german hyphenation
    a4paper, % paper format
    oneside, % one-sided pages
]{article}

% Code
\usepackage{listings} % source code
%\usepackage{bera} % optional: just to have a nice mono-spaced font
\usepackage{xcolor}

% colors
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\definecolor{lightgray}{rgb}{.9,.9,.9}
\definecolor{darkgray}{rgb}{.4,.4,.4}
\definecolor{purple}{rgb}{0.65, 0.12, 0.82}
\definecolor{orangered}{rgb}{255, 69, 0}

\lstset
{
    basicstyle=\footnotesize,
    numbers=left,
    numberstyle=\tiny\color{gray},
    stepnumber=2,
    backgroundcolor=\color{white},
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    frame=single,
    rulecolor=\color{black},
    tabsize=3,
    captionpos=b,
    breaklines=true,
    breakatwhitespace=false,
    title=\lstname,
    keywordstyle=\color{blue},
    commentstyle=\color{dkgreen},
    stringstyle=\color{mauve},
    morekeywords={},
    deletekeywords={}
}

\colorlet{punct}{red!60!black}
\definecolor{background}{HTML}{EEEEEE}
\definecolor{delim}{RGB}{20,105,176}
\colorlet{numb}{magenta!60!black}

\lstdefinelanguage{json}{
    basicstyle=\normalfont\ttfamily,
    numbers=left,
    numberstyle=\scriptsize,
    stepnumber=1,
    numbersep=8pt,
    showstringspaces=false,
    breaklines=true,
    frame=lines,
    backgroundcolor=\color{background},
    literate=
    *{0}{{{\color{numb}0}}}{1}
    {1}{{{\color{numb}1}}}{1}
    {2}{{{\color{numb}2}}}{1}
    {3}{{{\color{numb}3}}}{1}
    {4}{{{\color{numb}4}}}{1}
    {5}{{{\color{numb}5}}}{1}
    {6}{{{\color{numb}6}}}{1}
    {7}{{{\color{numb}7}}}{1}
    {8}{{{\color{numb}8}}}{1}
    {9}{{{\color{numb}9}}}{1}
    {:}{{{\color{punct}{:}}}}{1}
    {,}{{{\color{punct}{,}}}}{1}
    {\{}{{{\color{delim}{\{}}}}{1}
    {\}}{{{\color{delim}{\}}}}}{1}
    {[}{{{\color{delim}{[}}}}{1}
    {]}{{{\color{delim}{]}}}}{1},
}

% Tables
\usepackage{booktabs} % horizontal lines in tables
\usepackage{tabularx} % additional table functions (new environent tabularx)
\usepackage{ltablex}
%\usepackage{ltxtable} % long tabularx tables
\usepackage{multirow} % connect multiple rows in tables
\usepackage{array} % additional table functions
\usepackage{ragged2e} % adds function to center, left, right text

% Caption
\usepackage[font=small, labelfont=bf, justification=raggedright, format=hang]{caption}

\captionsetup[table]{position=below}
\captionsetup[figure]{position=below}

\begin{document}


\begin{lstlisting}[language=json,firstnumber=1,caption={Aufbau des JSON-Strings}]
{
"id": {
"board-id": 1,
"command-group-id": 2,
"command-id": 5 
},
"payload": {
}
}
\end{lstlisting}

\begin{table}[ht!]
    \centering
    \begin{tabular}{@{}lccccl@{}}
        \toprule
        Command Name &
        \multicolumn{4}{c}{ID} &
        Payload \\
        \midrule
        SetSpeed &
        1 &
        1 &
        0 &
        1 &
        speed \\
        \bottomrule
    \end{tabular}
    \caption{Auflistung aller Commands für die Kommunikation zwischen Raspberry Pi 1 und 2}
    \label{tab:Komponentenbeschreibung - Kommunikation - Commands}
\end{table}


\end{document}

答案1

为了确保单行标题不居中(这是的默认设置)caption,您可以在命令singlelinecheck=false\captionsetup或加载包时的选项中设置caption

\captionsetup{singlelinecheck=false}

或者

\usepackage[singlelinecheck=false]{caption}

包括singlelinecheck=false上述任一选项,输出将变为

输出

相关内容