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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10358
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