2

I have a table where I want more than one row in some cells. I am using parbox to achieve this but this makes some items in cells left aligned and some not. How can you fix this to make them all aligned the same way?

\documentclass{beamer}
\usepackage{multirow}
\begin{document}   
\begin{frame}
\frametitle{Test page}   
\resizebox{\textwidth}{!}{%
\begin{tabular}{|l||c|c|}

   \hline
               \multirow{3}{*}  & Column one & Column two  \\
   \hline
   \hline
        Row one&  \textcolor{gray}{$f(n) = n^2$}  & \parbox{5cm}{$f(n) = n^2$ \\ $f(n) = n^2$}\\
        Row two &  \parbox{7cm}{\textcolor{gray}{$g(n,S) = n\sqrt{\log (n/S)/\log\log(n/S)})$} \\$g(n) = n^3$ } & $g(n) = n^3$\\
        Row three & \textcolor{gray}{$f(n) = n^2$} & \parbox{5cm}{$f(n) = n^2$\\ $f(n) = n^2$}\\
   \hline
   \end{tabular}%
}   
\end{frame}    
\end{document}

Update. Following the advice in the comments I have changed the table a little to show another problem.

\resizebox{\textwidth}{!}{%
\begin{tabular}{|l||c|c|}   
   \hline
               \multirow{3}{*}  & Column one & Column two  \\
   \hline
   \hline
        Row one&  \textcolor{gray}{$g(n,S) = n\sqrt{\log (n/S)/\log\log(n/S)})$}  & \parbox{5cm}{\centering $f(n) = n^2$ \\ $f(n) = n^2$}\\
        Row two &  \parbox{7cm}{\textcolor{gray}{\centering $g(n,S) = n\sqrt{\log (n/S)/\log\log(n/S)})$} \\ \centering $g(n) = n^3$ } & $g(n) = n^3$\\
        Row three & \textcolor{gray}{$f(n) = n^2$} & \parbox{5cm}{\centering $f(n) = n^2$\\ $f(n) = n^2$}\\
   \hline
   \end{tabular}%
}

g(n,S) is still not quite aligned the same in the first and second rows of "Column one".

  • 1
    You can use \centering inside a \parbox\parbox{5cm}{\centering $f(n) = n^2$ \\ $f(n) = n^2$} – user11232 Oct 22 '13 at 11:11
  • 1
    Also, why \multirow{2}{*}? – user11232 Oct 22 '13 at 11:12
  • @HarishKumar I fixed the number of rows in \multirow, assuming I understand the syntax. – felix Oct 22 '13 at 11:24
  • @HarishKumar Thanks. The trick for row two is to do `Row two & \parbox{7cm}{\textcolor{gray}{ $g(n,S) = n\sqrt{\log (n/S)/\log\log(n/S)})$} \\ \centering$g(n) = n^3$ } & $g(n) = n^3$` . That is the centering goes in the second row of the cell, not the first. I updated the question to show another problem however. – felix Oct 22 '13 at 11:31
1

I recommend to use \multirow{} instead of \parbox{}.

enter image description here

\documentclass{beamer}

\usepackage{multirow}

\begin{document}

\begin{frame}
\frametitle{Test page}
\resizebox{\textwidth}{!}{%
    \begin{tabular}{|l||c|c|}
        \hline
            & Column one & Column two\\
        \hline
        \hline
        \multirow{2}{*}{Row one} & \multirow{2}{*}{$g(n,S) = n\sqrt{\log (n/S)/\log\log(n/S)})$} & $f(n) = n^2$ \\
                & & $f(n) = n^2$ \\
        \multirow{2}{*}{Row two} & $g(n,S) = n\sqrt{\log (n/S)/\log\log(n/S)})$ & \multirow{2}{*}{$g(n) = n^3$} \\
            & $g(n) = n^3$ & \\
        \multirow{2}{*}{Row three} & \multirow{2}{*}{$f(n) = n^2$} & $f(n) = n^2$\\
            & & $f(n) = n^2$ \\
        \hline
    \end{tabular}%
}
\end{frame}

\end{document}
3

I would recommend using parboxes that are bit narrower than your current settings. Thaat way, you won't have to use \resizebox to reduce the table's size, arguably making for a more-readable beamer page.

The code below also doesn't employ \multirow as I couldn't see a use for it. I do insert a couple of \\[2ex] spacing instructions to get more vertical separation between the three main rows.

enter image description here

\documentclass{beamer}
\begin{document}
\begin{frame}
\frametitle{Test page}
\begin{tabular}{|l||c|c|}
   \hline
   & Column one & Column two  \\
   \hline
   \hline
        Row one&  
        \textcolor{gray}{$g(n,S) = n\sqrt{\log (n/S)/\log\log(n/S)}$}  & 
        \parbox{2cm}{\centering $f(n) = n^2$ \\ $f(n) = n^2$}\\[2ex]
        Row two &  \parbox{6cm}{\textcolor{gray}{
           \centering $g(n,S) = n\sqrt{\log (n/S)/\log\log(n/S)}$} \\ 
           \centering $g(n) = n^3$ } 
        & $g(n) = n^3$\\[2ex]
        Row three & \textcolor{gray}{$f(n) = n^2$} & 
        \parbox{1.75cm}{\centering $f(n) = n^2$\\ $f(n) = n^2$}\\
   \hline
   \end{tabular}
\end{frame}
\end{document} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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