Graphics, Figures & TablesHow to use \fbox in a \caption with the subfig-package

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ge0rch
Posts: 3
Joined: Wed Apr 30, 2014 11:04 am

How to use \fbox in a \caption with the subfig-package

Post by ge0rch »

Hey,
i use \fbox{} inside a \caption{} and without \usepackage{subfig} everything works just fine. since i want to use subfigures i get an error:
! Argument of \@tempa has an extra } \caption{test \fbox{test}}

any suggestions? minimal working example:
_____________________________
\documentclass[12pt]{book}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{tikz}

\begin{document}
\begin{figure}[!ht]
\tikz{\node at (0,0) {TEST};}
\caption{test \fbox{test}}
\label{fig:test}
\end{figure}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

ge0rch
Posts: 3
Joined: Wed Apr 30, 2014 11:04 am

Re: How to use \fbox in a \caption with the subfig-package

Post by ge0rch »

Hey guys,
i didn't find a solution in ohter fora and wonder if you get the same error?
i hope the tikz line doesn't prevent the code to be treated as a mwe :)
ge0rch
Posts: 3
Joined: Wed Apr 30, 2014 11:04 am

How to use \fbox in a \caption with the subfig-package

Post by ge0rch »

Good things come to those who wait...
The problem comes along with \caption[]{}. Including the subfig-packages and a missing first parameter in the caption command won't work! why ever?
______________________________________________________________________________________
[1] works

Code: Select all

\documentclass[12pt]{book}
%\usepackage{subfig}           % comment out 
\usepackage{tikz}
\begin{document}
\begin{figure}[!ht]
\tikz{\node at (0,0) {TEST};}
\caption{test \fbox{test}}     % here: \caption[missing]{}
\label{fig:test}
\end{figure}
\end{document}
______________________________________________________________________________________
[2] works not

Code: Select all

\documentclass[12pt]{book}
\usepackage{subfig}
\usepackage{tikz}
\begin{document}
\begin{figure}[!ht]
\tikz{\node at (0,0) {TEST};}
\caption{test \fbox{test}}      % here: \caption[missing]{}
\label{fig:test}
\end{figure}
\end{document}
______________________________________________________________________________________
[3] works

Code: Select all

\documentclass[12pt]{book}
\usepackage{subfig}
\usepackage{tikz}
\begin{document}
\begin{figure}[!ht]
\tikz{\node at (0,0) {TEST};}
\caption{test}                  % here: \caption[missing]{}, no \fbox{}
\label{fig:test}
\end{figure}
\end{document}
______________________________________________________________________________________
[4] works

Code: Select all

\documentclass[12pt]{book}
\usepackage{subfig}
\usepackage{tikz}
\begin{document}
\begin{figure}[!ht]
\tikz{\node at (0,0) {TEST};}
\caption[solution]{test \fbox{test}}   % here: \caption[not missing]{}
\label{fig:test}
\end{figure}
\end{document}
______________________________________________________________________________________
Post Reply