Graphics, Figures & Tables ⇒ How to use \fbox in a \caption with the subfig-package
How to use \fbox in a \caption with the subfig-package
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}
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
Re: How to use \fbox in a \caption with the subfig-package
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

How to use \fbox in a \caption with the subfig-package
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}