Text FormattingVerbatim Text inside a Section

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
buzon
Posts: 7
Joined: Tue Jan 17, 2012 1:08 am

Verbatim Text inside a Section

Post by buzon »

Hello,

I read many posts but couldn't get the clear conclusion on the topic. I need to include the varbati text inside the sections, like for example tables. I would need that text to be multiline...
Let's assume this simple example - how to make any text there as verbatim? ( I marked the sections wiht %here in the comments)

Code: Select all

\documentclass[10pt,a4paper]{article}

\usepackage[table]{xcolor} % for colors in tables
\usepackage{tabularx} 
\usepackage{color} % for font color
\usepackage{caption}
\usepackage{multirow}  % for multirows in tables

\begin{document}

\begin{table}
\begin{tabular}{|c| p{9.5cm}|}
\hline
\multicolumn{2}{|c|}{ \cellcolor{gray} \textbf{ \textcolor{white}{ Title_here }} } \\   %here
\hline
\hline
\multicolumn{2}{|c|}{ \cellcolor{yellow} \textbf{Medium} } \\
\hline Foo & bar \\ 
\hline 
\end{tabular}
\caption{ Title_here }  %here
\end{table}

\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.

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

Verbatim Text inside a Section

Post by Stefan Kottwitz »

Hi,

you could use the examplep package, it offeres several ways for typesetting verbatim text, also in macro arguments and tables.

For example:

Code: Select all

\usepackage[Q=yes]{examplep}
...
\begin{table}
\begin{tabular}{|c| p{9.5cm}|}
\hline
\multicolumn{2}{|c|}{ \cellcolor{gray} \textbf{ \Q{\\textcolor{white}{ Title_here }}} } \\   %here
\hline
\hline
\multicolumn{2}{|c|}{ \cellcolor{yellow} \textbf{Medium} } \\
\hline Foo & bar \\
\hline
\end{tabular}
\caption{\protect\Q{Title_here}}  %here
\end{table}
table.png
table.png (7.12 KiB) Viewed 3031 times
Stefan
LaTeX.org admin
buzon
Posts: 7
Joined: Tue Jan 17, 2012 1:08 am

Verbatim Text inside a Section

Post by buzon »

Stefan, thank you for support. The solution works pretty well, but rather for small, one-line sections.
Do you have any idea how to put the longer text inside the table, for the text to not be interpreted (the characters like /, _, @, # etc. often happen there) but also to be somehow 'controlled' inside the table, to not screw the page? (esp. when I tend to use footers, page numbers etc.)

Check how this example is rendered, to understand what I mean.

Thanks in advance for any clues!

Code: Select all

\documentclass[10pt,a4paper]{article}

\usepackage[table]{xcolor} % for colors in tables
\usepackage{tabularx} 
\usepackage{color} % for font color
\usepackage{caption}
\usepackage{multirow}  % for multirows in tables

\usepackage[Q=yes]{examplep}

\begin{document}

\begin{table}
\begin{tabular}{|c| p{9.5cm}|}
\hline
\multicolumn{2}{|c|}{ \cellcolor{gray} \textbf{ \Q{\\textcolor{white}{ Title_here }}} } \\   %here
\hline
\hline
\multicolumn{2}{|c|}{ \cellcolor{yellow} \textbf{Medium} } \\
\hline Description & \Q{Text  new line \\
This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. 
This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. 

}\\
\hline Foo & bar \\
\hline
\end{tabular}
\caption{\protect\Q{Title_here}}  %here
\end{table}

\begin{table}
\begin{tabular}{|c| p{9.5cm}|}
\hline
\multicolumn{2}{|c|}{ \cellcolor{gray} \textbf{ \Q{\\textcolor{white}{ Title_here }}} } \\   %here
\hline
\hline
\multicolumn{2}{|c|}{ \cellcolor{yellow} \textbf{Medium} } \\
\hline Description & \Q{this table should be visible
}\\
\hline Foo & bar \\
\hline
\end{tabular}
\caption{\protect\Q{Title_here}}  %here
\end{table}

\end{document}
Post Reply