Search code examples
latexcaption

LaTex: How to change caption on figures from "Figure 1:" to "Figure 1 |"


I have the following LaTex code below which generates a figure of a histogram:

\documentclass[review,12pt]{elsarticle}

\usepackage{lineno,hyperref}

\usepackage[utf8]{inputenc}
\usepackage[dvipsnames]{xcolor}
\usepackage{amssymb, lipsum, color}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{comment}
\usepackage{smartdiagram}
\usetikzlibrary{shapes.geometric}
\usepackage{float}

\begin{document}

\begin{figure}[H]
\centering
\includegraphics[scale=0.8]{Histogram A.jpg}
\caption{Histogram Title}\label{Histogram A}
\end{figure}

\end{document}

I have attached a picture of the histogram here: Histogram A

The caption on the histogram figure will start with Figure 1: Histogram Title. How do I change this to Figure 1 | Histogram Title? Ie. how do I replace the colon sign to a pipe sign?

Many thanks in advance!


Solution

  • Using the caption package:

    \documentclass[review,12pt]{elsarticle}
    
    \usepackage{lineno,hyperref}
    
    \usepackage[utf8]{inputenc}
    \usepackage[dvipsnames]{xcolor}
    \usepackage{amssymb, lipsum, color}
    \usepackage{graphicx}
    \usepackage{subfigure}
    \usepackage{comment}
    \usepackage{smartdiagram}
    \usetikzlibrary{shapes.geometric}
    \usepackage{float}
    
    \usepackage{caption}
    \DeclareCaptionLabelSeparator{bar}{\space\textbar\space}
    \captionsetup{labelsep=bar}
    
    \begin{document}
    
    \begin{figure}[htbp]
    \centering
    \includegraphics[scale=0.8]{example-image-duck}
    \caption{Histogram Title}\label{Histogram A}
    \end{figure}
    
    \end{document}
    

    enter image description here