Graphics, Figures & TablesVerbatim text in a figure caption

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
neeraj2608
Posts: 3
Joined: Mon Apr 06, 2009 4:07 pm

Verbatim text in a figure caption

Post by neeraj2608 »

Hi,
I'm new to Latex and I want to put a long URL in a figure caption without having to escape every special character like "_" with a backslash. Since \verb cannot be used in a command argument, I tried putting the URL between the \begin{verbatim} and \end{verbatim} commands. Unfortunately, it doesn't seem to work. The error MiKTeX 2.7 gives me is:
LaTeX Error: Something's wrong--perhaps a missing \item.
Here is my code:

Code: Select all

\begin{figure}[h!]
  \begin{center}\
    \includegraphics{my image name}
    \caption{Visual processing areas of the brain. Source:
    \begin{verbatim}
      http://thebrain.mcgill.ca/flash/a/a_02/a_02_cr/a_02_cr_vis/a_02_cr_vis_3c.jpg
    \end{verbatim}}
  \end{center}
\end{figure}
What am I doing wrong? Does Latex not allow using verbatim commands in a figure caption?

Thanks.

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

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Verbatim text in a figure caption

Post by Stefan Kottwitz »

Hi,

in this case you could use the url package:

Code: Select all

\usepackage{url}
...
\caption{Visual processing areas of the brain. Source:
  \protect\url{http://thebrain.mcgill.ca/flash/a/a_02/a_02_cr/a_02_cr_vis/a_02_cr_vis_3c.jpg}}
Btw. I would use \centering instead of the center environment inside a figure environment, see center vs. \centering for an explanation.

Stefan
LaTeX.org admin
neeraj2608
Posts: 3
Joined: Mon Apr 06, 2009 4:07 pm

Verbatim text in a figure caption

Post by neeraj2608 »

Stefan_K wrote:Hi,

in this case you could use the url package:

Code: Select all

\usepackage{url}
...
\caption{Visual processing areas of the brain. Source:
  \protect\url{http://thebrain.mcgill.ca/flash/a/a_02/a_02_cr/a_02_cr_vis/a_02_cr_vis_3c.jpg}}
Btw. I would use \centering instead of the center environment inside a figure environment, see center vs. \centering for an explanation.

Stefan
Hi Stefan, thank you for your help!
Post Reply