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.

I can't find a way to vertically center a single line within a table cell.

Take a look at this screenshoot:

enter image description here

I'd like to vertically center the text within the bottom right cell and I just can't find a way to do it. I tried \usepackage{array} but I couldn't figure out how to apply the \centering\arraybackslash, which seems to align things vertically within cells, just to this single cell.

(I'm also not sure why the right border is missing for this cell.)

Here is the LaTeX code that generates this table:

\documentclass{article}

\usepackage[left=1cm,top=1cm,right=1cm,bottom=1cm,nohead,nofoot]{geometry}

\usepackage[pdftex]{hyperref}
\usepackage{verbatim}
\usepackage{listings}
\usepackage{array}

\hypersetup{colorlinks}

\lstset{basicstyle=\ttfamily}

\pagestyle{empty}

% -----------------------------------------------------------------------

\begin{document}

\begin{tabular}{|p{5.5cm}|p{12.2cm}|}
\hline
\large\textbf{Redirection} & \large\textbf{Description} \\
\hline
\verb|> file| & Redirect standard output (stdout) to a file. \\
\hline
\verb|1> file| & Same as \verb|> file|. \verb|1| is the default file descriptor for stdout. \\
\hline
\verb|2> file| & Redirect standard error (stderr) to a file. \verb|2| is the default file descriptor for stderr. \\
\hline
\verb|>> file| & Append stdout to a file. \\
\hline
\verb|2>> file| & Append stderr to a file. \\
\hline
\verb|&> file| & Redirect stdout and stderr to a file. \\
\hline
\verb|>file 2>&1| & Another way to redirect both stdout and stderr to a file. This \textbf{is not} the same as \verb|2>&1 >file|. \textbf{Redirection order matters!} \\
\hline
\verb|> /dev/null| & Discard stdout. \\
\hline
\verb|2> /dev/null| & Discard stderr. \\
\hline
\verb|&> /dev/null| & Discard stdout and stderr. \\
\hline
\verb|< file| & Redirect the contents of the file to the stdin. \\
\hline
\verb|<< EOL| \\
\verb|foo| \\
\verb|bar| \\
\verb|baz| \\
\verb|EOL| & Redirect a bunch of lines to the stdin. \\
\hline
\end{tabular}

\end{document}
share|improve this question
    
Please provide a complete code starting from \documentclass... .....\end{document} –  Harish Kumar Sep 9 '12 at 23:11
    
@HarishKumar I just updated my code example. I had made an error earlier and it had missing symbols. –  Peteris Krumins Sep 9 '12 at 23:19
add comment

2 Answers

You can use the m option provided by the array package to vertically centre the material in table columns. However, you have another problem. Using \\ without a preceding ampersand creates a row with only one column. This is why part of the right edge of the table is missing. Instead, you could use \par to insert a line break without moving to the next line of the table.

\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{|m{5.5cm}|m{12cm}|}
\hline
\large\textbf{Redirection} & \large\textbf{Description} \\
\hline
\verb|> file| & Redirect standard output (stdout) to a file. \\
\hline
\verb|1> file| & Same as \verb|> file|. \verb|1| is the default file descriptor for stdout. \\
\hline
\verb|2> file| & Redirect standard error (stderr) to a file. \verb|2| is the default file descriptor for stderr. \\
\hline
\verb|>> file| & Append stdout to a file. \\
\hline
\verb|2>> file| & Append stderr to a file. \\
\hline
\verb|&> file| & Redirect stdout and stderr to a file. \\
\hline
\verb|>file 2>&1| & Another way to redirect both stdout and stderr to a file. This \textbf{is not} the same as \verb|2>&1 >file|. \textbf{Redirection order matters!} \\
\hline
\verb|> /dev/null| & Discard stdout. \\
\hline
\verb|2> /dev/null| & Discard stderr. \\
\hline
\verb|&> /dev/null| & Discard stdout and stderr. \\
\hline
\verb|< file| & Redirect the contents of the file to the stdin. \\
\hline
\verb+<< EOL+\par
\verb+foo+\par
\verb+bar+\par
\verb+baz+\par
\verb+EOL+
 & Redirect a bunch of lines to the stdin. \\
\hline
\end{tabular}
\end{document}

table

share|improve this answer
    
My terminal stripped some of the symbols when I made the paste. I just updated my question with a full document. I actually do have '\\'. ... So I just tried your suggestions of using m and using \par and it worked, my document now looks perfect! Thanks a lot! –  Peteris Krumins Sep 9 '12 at 23:22
add comment

There are some mistakes. You are ending a tabularline with \. It should be \\. Also you are having two columns. Irrespective of the data, you have to use ampersands like (say)

\verb|foo|& \\

This is the reason you are not getting right border.

To center the the particular cell you can use multirow. Put \usepackage{multirow} in the preamble and use

\verb+<< EOL+& \multirow{5}*{Redirect a bunch of lines to the stdin.} \\
    \verb+foo+&\\
    \verb+bar+&\\
    \verb+baz+&\\
    \verb+EOL+ &  \\
    \hline

Full code:

\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|p{5.5cm}|p{12cm}|}
\hline
\large\textbf{Redirection} & \large\textbf{Description} \\
\hline
\verb|> file| & Redirect standard output (stdout) to a file. \\
\hline
\verb|1> file| & Same as \verb|> file|. \verb|1| is the default file descriptor for stdout. \\
\hline
\verb|2> file| & Redirect standard error (stderr) to a file. \verb|2| is the default file descriptor for stderr. \\
\hline
\verb|>> file| & Append stdout to a file. \\
\hline
\verb|2>> file| & Append stderr to a file. \\
\hline
\verb|&> file| & Redirect stdout and stderr to a file. \\
\hline
\verb|>file 2>&1| & Another way to redirect both stdout and stderr to a file. This \textbf{is not} the same as \verb|2>&1 >file|. \textbf{Redirection order matters!} \\
\hline
\verb|> /dev/null| & Discard stdout. \\
\hline
\verb|2> /dev/null| & Discard stderr. \\
\hline
\verb|&> /dev/null| & Discard stdout and stderr. \\
\hline
\verb|< file| & Redirect the contents of the file to the stdin. \\
\hline
\verb+<< EOL+& \multirow{5}*{Redirect a bunch of lines to the stdin.} \\
\verb+foo+&\\
\verb+bar+&\\
\verb+baz+&\\
\verb+EOL+ &  \\
\hline
\end{tabular}
\end{document}

enter image description here

share|improve this answer
    
I'm sorry, my terminal accidentally stripped some formatting. I've now updated my question with correct latex code. Please try compiling my test. –  Peteris Krumins Sep 9 '12 at 23:19
    
Your solution is also great. Thanks! –  Peteris Krumins Sep 9 '12 at 23:26
add comment

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.