环境列表上方的标题和下方的图例

环境列表上方的标题和下方的图例

我想知道如何在环境框架下方放置图例listings,这样它就不会破坏我拥有的其他两种列表的设置。图例必须没有数字,与框架左边距对齐,固定名称为“Fonte:”,框架下方的空间等于 10pt,图例下方到文本的空间等于 18pt,就像我对表格所做的那样,例如:

在此处输入图片描述

belowskip=xpt我知道我可以使用列表设置中的来控制图例和框架之间的距离。

我正在使用abntex2类。使用以下设置,我得到了不想要的结果:

在此处输入图片描述

\renewcommand{\baselinestretch}{1.5}
\setlength{\beforechapskip}{-\onelineskip}
\setlength{\afterchapskip}{\onelineskip} 

\renewcommand{\foottextfont}{\small}              % default fontsize for document = 12pt                    
\renewcommand{\IBGEtabfontsize}{\small}
\renewcommand{\ABNTEXfontereduzida}{\foottextfont}
\captionsetup{justification=centering,labelfont=small,textfont=small,skip=4pt}

  \hangcaption
  \captiondelim{~\textendash~}
 %\captionnamefont{\ABNTEXfontereduzida}
 %\captiontitlefont{\ABNTEXfontereduzida}

\newcommand{\IBGEtabfontsize}{\ABNTEXfontereduzida}
\AtBeginDocument{%
   \newcommand{\configurecaptions}{\captionstyle[\raggedright]{}}
   \newcommand{\configureseparator}{\captiondelim{: }}
   \newsavebox{\myptabbox}
   \newlength{\myptabboxwidth}
   \newcommand{\IBGEtab}[3]{%
   \savebox{\myptabbox}{{\IBGEtabfontsize #2}}%
   \settowidth{\myptabboxwidth}{\usebox{\myptabbox}}%
   \centering%
   \parbox{\myptabboxwidth}{%
   \configurecaptions
     #1%
     \par%
   {\IBGEtabfontsize%
     #2%
      }%
    \par%
     #3}%
          }
\let\ibgetab\IBGEtab
}

\makeatletter
   \newcommand{\fonte}[2][\fontename]{%
     \M@gettitle{#2}%
     \memlegendinfo{#2}%
     \par
     \begingroup
        \@parboxrestore
          \if@minipage
          \@setminipage
          \fi
          \ABNTEXfontereduzida
          \configureseparator
         \@makecaption{\ABNTEXfontereduzida #1}{\ignorespaces\ABNTEXfontereduzida #2}\par
      \endgroup}
        \makeatother

\makeatletter
        \newcommand{\nota}[2][\notaname]{\fonte[#1]{#2}}
\makeatother

    \AtEndPackage{caption}{
      \AtBeginDocument{%
        \DeclareCaptionLabelSeparator{barr}{~\textendash~}
        \DeclareCaptionFont{ABNTEXfontereduzida}{\ABNTEXfontereduzida}
          \captionsetup{format=hang,
                        labelseparator=barr,
                        %labelfont=ABNTEXfontereduzida,
                        %font=ABNTEXfontereduzida
                        }
       \renewcommand{\configurecaptions}{%
                     \captionsetup{justification=justified,%
                     singlelinecheck=false}}
       \renewcommand{\configureseparator}{\captionsetup{labelsep=colon}}
      }
    }


% For list of tables and figures********************

 \newcommand{\Caption}[1]{ %
 \begin{Spacing}{1.5} %
        \caption{#1} %
        \end{Spacing} %
}

\newcommand{\Fonte}[2][\fontename]{ %
% \vspace{-3pt}
 \vspace{10pt}
  \fonte[#1]{#2}
  \vspace{-5pt}
}

% Notes below legend for tables and figures*********************
\newcommand{\Nota}[2][\notaname]{\fonte[#1]{#2}}

\usepackage{listings}   % New list of Listings******************

\renewcommand{\lstlistingname}{Código}                                 
\renewcommand{\lstlistlistingname}{Lista de Códigos}
\newfloat[chapter]{codigo}{loc}{\lstlistingname}                           % lol  (??)
\newlistof{listofcodigos}{loc}{\lstlistlistingname}
\newlistentry{codigo}{loc}{0}

\counterwithout{codigo}{chapter} % ABNT
\renewcommand{\cftcodigoname}{\lstlistingname\space}
\renewcommand*{\cftcodigoaftersnum}{\hfill--\hfill}

% Print new list of listings (Lista de Códigos)
\newcommand{\imprimirlistadecodigos}{ %
        \pdfbookmark[0]{\lstlistlistingname}{loc}
        \begin{KeepFromToc}                      
            \listofcodigos
        \end{KeepFromToc}
    \cleardoublepage %
}

% Listings settings******************************

    \lstset{
   %float=tp,                                                          
    extendedchars=false,
    inputencoding=utf8,
    language=[LaTeX]{TeX},
   %linewidth=13cm,
    backgroundcolor=\color{SkyBlue},
    keywordstyle=\color{black},
    rulecolor=\color{black},                                     
    commentstyle=\color{black}\ttfamily,
    basicstyle=\footnotesize\normalfont\ttfamily,                
    numberstyle=\small,                                          
    frame=single,                                                
    framesep=2pt,
   %rulesep=2pt,                                                
    xleftmargin=1.5cm,                                          
    xrightmargin=1.5cm,                                         
   %framexleftmargin=2pt,                                       
   %framexrightmargin=2pt,
   %framextopmargin=,
   %framexbottommargin=
    stepnumber=1,                                               
    numbers=left,                                               
    numbersep=8pt,                                              
    tabsize=2,                                                  
    upquote=true,
    columns=[c]flexible,                                        
    showstringspaces=false,
    breaklines=true,
   %frameround=ftff,                                            
    belowskip=0pt,
    belowcaptionskip=18pt,
   %numberbychapter=false,                                      
    breaklines=true,                                            
    upquote=false                                               
}

测试:

\documentclass[12pt,a4paper,openright,oneside,dvipsnames,english,brazil]{abntex2}
\usepackage{caption}                                                                  
\usepackage{tocloft}                                                                  
\usepackage{etoolbox}                                                               
\usepackage{lastpage}                                                               
\usepackage{graphicx}                                                               
\usepackage{calc}
\usepackage[prologue]{xcolor}

\begin{document}
\begin{codigo}[h!]
   \Caption{Código do Exemplo 1}\label{cod:cod1}
      \begin{lstlisting}
        \begin{document}
               Teste
         \end{document}
      \end{lstlisting}%
\Fonte{Elaborado pelo autor}
\end{codigo}
\end{document}   

答案1

谢谢你,约翰。我只有一个非常糟糕的解决方案。

\newcommand{\fontcod}{%
\hfill\\
\begin{minipage}[c]{13.2cm}
Fonte: Just me.
\end{minipage}\\
}

\lstset{
    float=tb,                                          
    extendedchars=false,
    inputencoding=utf8,
    language=[LaTeX]{TeX},
    linewidth=13cm,
    backgroundcolor=\color{SkyBlue},
    keywordstyle=\color{black},
    rulecolor=\color{black},                           
    basicstyle=\footnotesize\normalfont\ttfamily,      
    numberstyle=\small,                                
    frame=single,                                      
    framesep=2pt,
    xleftmargin=0cm,                                      
    xrightmargin=0cm,                                     
    stepnumber=1,                                    
    numbers=left,                                    
    numbersep=8pt,                                   
    tabsize=2,                                       
    upquote=true,
    columns=[c]flexible,                             
    showstringspaces=false,
    breaklines=true,
    belowskip=0pt,
    breaklines=true,                                                
    upquote=false                                          
}

\begin{document}

\begin{codigo}[h]
\Caption{\label{cod1}Test}
\centering
   \begin{tabular}{c}
      \begin{minipage}[t]{13cm}
          \begin{lstlisting}
                A very ugly solution.
          \end{lstlisting}
      \end{minipage}\\
   \fontcod
   \end{tabular}
\end{codigo}

\end{document}

答案2

编辑:\begin{minipage}[l]{13.2cm}\begin{minipage}[c]{13.2cm}中切换\fontcod

但是使用上面的代码打印结果是左对齐的(即使编辑了错误的参数):

在此处输入图片描述

相关内容