9 Comments

  1. Sper

    Hi Tom,

    I’m trying to wrap the contents of some cells of a table without much luck.
    Here’s my table, and the solution I am currently using:

    \documentclass[12pt,oneside]{book}
    \begin{document}
    \begin{table}[!h]
    \centering
     \begin{tabular}{|c|c|c|c|c|}
      \hline
      SNR & \multicolumn{4}{|c|}{Relative error re } \\
      \cline{2-5}
      in gradient & method number 1 & method number 2 & method number 3 & method number 4\\ \hline\hline
      12.5186 & 0.0260 & 0.1063 & 0.0314 & 0.0287 \\ \hline
     \end{tabular}
    \end{table}
    This text is added to highlight the fact that the table exceeds the page margins. What would be a smarter way to wrap some cells (namely, my headers) in such a way that the overall table stays within the page margins? Thanks!
    \end{document}

    Could you please let me know if there is an easier way of getting the same result, without shrinking the size of the characters?

    I hope pasting directly from LaTeX is okay, it’s the best way in which I could think of showing you my problem.

    Thank you kindly for taking the time!

    Sper

    • Hi Sper,

      Thank you for the code, that made things a lot easier. I suggest using the fixed width column type m. You’ll find your code below with some changes. First, define a new columntype that is centered horizontally (m) and vertically (centering). Replace \\ by \tabularnewline to avoid “Missplaced \noalign” errors. And, use *{number}{type} to avoid repeating the same columntype over and over again.

      \documentclass[12pt,oneside]{book}
      \usepackage{array}
      \newcolumntype{M}{>{\centering}m{2cm}}
      \begin{document}
      \begin{table}[ht]
      \centering
      \begin{tabular}{*{5}{|M}|}
      \hline
      SNR & \multicolumn{4}{|c|}{Relative error re }
      \tabularnewline
      \cline{2-5}
      in gradient & method number 1 & method number 2 & method number 3 & method number 4 \tabularnewline
       \hline\hline
      12.5186 & 0.0260 & 0.1063 & 0.0314 & 0.0287 \tabularnewline
      \hline
      \end{tabular}
      \caption{bla}
      \end{table}
      This text is added to highlight the fact that the table exceeds the page margins. What would be a smarter way to wrap some cells (namely, my headers) in such a way that the overall table stays within the page margins? Thanks!
      \end{document}

      Best, Tom.

  2. I’m trying to use a graphic alongside a numbered list, but it just dumps the graphic at the end of the file. This is my code –

    \begin{wrapfigure}{r}{0.5\linewidth}
    \centering
    % \rule{0.9\linewidth}{0.75\linewidth}
    \includegraphics{images/bse1.png}
    \caption{Dummy figure.}
    \label{fig:myfig}
    \end{wrapfigure}
    
    \begin{enumerate}
    \item Lie down. Flatten your right breast by placing a pillow under your right
      shoulder. Place your right arm behind your head. 
    \end{enumerate}

    How can I do it please Tom?
    Sharon.

    • tom

      Try the minipage environment:

      \documentclass[11pt]{article}
      \begin{document}
      
      \begin{minipage}{0.45\linewidth}
      \rule{0.75\linewidth}{0.75\linewidth}
      \end{minipage}
      \begin{minipage}{0.45\linewidth}
      \begin{enumerate}
      \item First item
      \item Second item
      \end{enumerate}
      \end{minipage}
      
      \end{document}
    • tom

      Hi there,

      It works exactly the same way as shown in the example for article. Just give it a try and let me know if you get stuck.

      Best, Tom

Leave a Reply to boudiccas Cancel reply