Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

verbatim environment is not working in figure caption. Checked How to put \verb command inside of \textbf{} block? and Verbatim inside a command is not working.

\documentclass[11pt, double space]{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{color}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[english]{babel}
\usepackage[autostyle, english = american]{csquotes}
\MakeOuterQuote{"}
\usepackage{cprotect}

\begin{document}
\begin{figure}[!h]
\caption{Sample 1 \cprotect\begin{verbatim} \tau(A) = e^{\chi_0A/(KD_p(K+A))} \end{verbatim} per hour.}
\label{fig:singlecell_chemo}
\end{figure}

\end{document}

I have tried cprotect package also. Any help.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

You can also use the verbatimbox package. In this case, you put the verbatim material into a verbbox before invoking figure, and then recall it with \theverbbox inside the figure.

\documentclass[11pt, double space]{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{color}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[english]{babel}
\usepackage[autostyle, english = american]{csquotes}
\MakeOuterQuote{"}
\usepackage{verbatimbox}

\begin{document}
\begin{verbbox}\tau(A) = e^{\chi_0A/(KD_p(K+A))} \end{verbbox}

\begin{figure}[!h]
\caption{Sample 1 \theverbbox per hour.}
\label{fig:singlecell_chemo}
\end{figure}

\end{document}

p.s. version 3.01 of verbatimbox just hit the streets. It finally has "real" documentation.

share|improve this answer

You must use \cprotect before \caption.

\documentclass[11pt, double space]{article}
\usepackage{graphicx}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{cprotect}
\begin{document}
\begin{figure}[!ht]
\cprotect\caption{Sample 1 \verb+\tau(A) = e^{\chi_0A/(KD_p(K+A))}+  per hour.}
\label{fig:singlecell_chemo}
\end{figure}

\end{document}

BTW: Don't use the environment center inside figure. When should we use \begin{center} instead of \centering?

share|improve this answer
    
Daniel: I have used \cprotect before caption. But LaTeX Error: Something's wrong--perhaps a missing \item. Any ideas? –  Balaji Apr 26 '13 at 6:44
    
@Balakrishnan: Please see: sharelatex.com/project/516b92597da65fe1772089d5 –  Marco Daniel Apr 26 '13 at 7:03

\cprotect needs to be specified before \caption:

\cprotect\caption{Sample 1 \verb|\tau(A) = e^{\chi_0A/(KD_p(K+A))}| per hour.}

Then \cprotect puts the argument of \caption inside a file and uses the file loading command as safer argument for \caption.

Also I have used \verb for use of verbatim inside a text line.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.