1

I use figures and listings in a document. By default, the identifier "Figure 1" is set in bold, while "Listing 1" is normal. For consistent looks I would like to have either everythin bold or normal. How?

edit: MWE (without the solution):

\documentclass{article}
\usepackage{listings}
\lstset{
language=C
}

\begin{document}

\begin{lstlisting}[
   caption={[short] long long long.},
   label={lst1}
]
int main ( void )
{
   return 0;
}
\end{lstlisting}

\end{document}

Documentclass is IOS-Book-Article which is based on article as far as I can tell. You find it here

  • 1
    Welcome to TeX.SX! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – m0nhawk Jul 8 '13 at 13:57
  • If you are using listing package, probably \renewcommand{\listingname}{\bfseries Listing} will do the job. Otherwise MWE is required. – Jagath Jul 8 '13 at 13:59
  • @blackburn: Thank you. I was preparing a MWE while you answered ;). The correct line is ´\renewcommand{\lstlistingname}{{\bfseries Listing}}´. Your answer lead me to search for the right words. Make it an answer to accept that. – steffen Jul 8 '13 at 14:11
  • now the number is not printed bold, but I'll figure that out... – steffen Jul 8 '13 at 14:13
  • @steffen: Give: \renewcommand{\lstlistingname}{\bfseries Listing} instead of \renewcommand{\lstlistingname}{{\bfseries Listing}}. The extra grouping inside definition prevents that bold. – Jagath Jul 8 '13 at 14:15
2

Try:

\renewcommand{\lstlistingname}{\bfseries Listing}
\makeatletter
\def\fnum@lstlisting{%
  \lstlistingname
  \ifx\lst@@caption\@empty\else~\thelstlisting\normalfont\fi}%
\makeatother

In listings package, \fnum@lstlisting macro makes the caption name and number bold. But, to make the rest of the caption non-bold, we need to add \normalfont in this definition.

| improve this answer | |
  • 1
    Add {\bfseries before \lstlistingname and } after \fi; this avoids redefining \lstlistingname and issuing \normalfont. – egreg Jul 8 '13 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.