Adding Shape and Symbol to Figure Captions in LaTeX

As an extension to my previous post on adding solid or dashed lines to figure captions in LaTeX documents, a similar method can be used to add different types of geometric markers.

figuremarkercaption

Simply include the package tikz along with the shapes library, which should be part of most standard LaTeX builds, then define a command to represent the type of marker you wish to use. The following code shows an example of the sorts of marker shapes that can be produced and then placed in the text of your document using your newly defined commands.

An example of the lines that can be created and the corresponding LaTeX code is shown below. Shapes such as circle, ellipses and diamonds have their own commands, while other such as square and triangles can be drawn using the regular polygon command.

Example of inline markers in LaTeX.

Example of inline markers / symbols in LaTeX.


\documentclass{report}
\usepackage{color}
\usepackage{tikz}
\usetikzlibrary{shapes}
%
\begin{document}
\newcommand{\markerone}{\raisebox{0.5pt}{\tikz{\node[draw,scale=0.4,circle,fill=black!20!blue](){};}}}
\newcommand{\markertwo}{\raisebox{0pt}{\tikz{\node[draw,scale=0.3,regular polygon, regular polygon sides=3,fill=black!45!green,rotate=180](){};}}}
\newcommand{\markerthree}{\raisebox{0.5pt}{\tikz{\node[draw,scale=0.3,regular polygon, regular polygon sides=3,fill=black!10!red,rotate=0](){};}}}
\newcommand{\markerfour}{\raisebox{0.5pt}{\tikz{\node[draw,scale=0.4,regular polygon, regular polygon sides=4,fill=none](){};}}}
\newcommand{\markerfive}{\raisebox{0pt}{\tikz{\node[draw,scale=0.4,diamond,fill=black!10!gray](){};}}}
\newcommand{\markersix}{\raisebox{0.6pt}{\tikz{\node[draw,scale=0.3,circle,fill=black!100!](){};}}}

\noindent This is a blue filled circle \markerone ;\\
This is an inverted green triangle \markertwo ;\\
This is a red triangle \markerthree ;\\
This is an unfilled square \markerfour ;\\
This is a grey diamond \markerfive ;\\
This is a black filled circle \markersix ;\\

\begin{figure}[h]
\caption{This is an inverted green triangle in a figure caption (\protect\markertwo).}
\end{figure}
\end{document}

In the above example the raise box command is used to offset the objects so that they are centred with the text. Of course this can be changed to represent any relative positioning you might desire.

Note: in order to use these commands in figure caption it is necessary to preface your defined commands with \protect to ensure LaTeX interprets the command properly.

Line functionality is only a very small part of the tikz package. For further possibilities please see https://en.wikibooks.org/wiki/LaTeX/PGF/TikZ.

One thought on “Adding Shape and Symbol to Figure Captions in LaTeX

  1. Ernest

    for this to work with the polygons, I needed to make the following change:

    \usetikzlibrary{shapes}

    |
    |
    v

    \usetikzlibrary{shapes.geometric}

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *