Graphics, Figures & TablesIncrease Row Width and Wrap Text

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
upani1982
Posts: 43
Joined: Wed May 12, 2010 11:42 am

Increase Row Width and Wrap Text

Post by upani1982 »

Hi All,

I need your suggestion how to increase row width in the second row of the table and other rows should not be changed.

Code: Select all

\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{rrrrrr}
    \addlinespace
    \toprule
          &       & \multicolumn{2}{c}{ Maximum Eigenvalue} & \multicolumn{2}{c}{ Using Maximum Trace} \\
    \midrule
    Commodity & Lag Length & \multicolumn{1}{c}{H0: Rank=0 Vs H1: Rank =1} & \multicolumn{1}{c}{H0: Rank=1 Vs H1: Rank =2} & \multicolumn{1}{c}{H0: Rank=0 Vs H1: Rank =1} & \multicolumn{1}{c}{H0: Rank=1 Vs H1: Rank =2} \\
    Gold  & 10    & 8.82  & 0.14  & 8.96  & 0.14 \\
    Silver & 7     & 39.2  & 3.57  & 42.76 & 3.57 \\
    Aluminum & 5     & 50.91 & 3.2   & 54.11 & 3.2 \\
    Copper & 10    & 105.34 & 2.91  & 108.25 & 2.91 \\
    Lead  & 10    & 30.67 & 3.81  & 34.48 & 3.81 \\
    Nickel & 10    & 26.48 & 5.43  & 31.9  & 5.43 \\
    Zinc  & 9     & 38.54 & 3.66  & 42.19 & 3.66 \\
    Crude Oil & 9     & 21.55 & 4     & 25.55 & 4 \\
    Natural Gas & 4     & 9.66  & 2.51  & 12.17 & 2.51 \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%
If i run the above code the second column H0: Rank=1 Vs H1: Rank =2 is getting long, whereas i want them in the following order.

H0: Rank=1 H0: Rank=1
Vs Vs
H1: Rank =2 H1: Rank =2

I am confused and searched Google but no convincing answers got so far. Your valuable suggestion is required for the same

Attached excel file shows the table i want to create in latex.
With sincere regards,
Upananda
Attachments
table.pdf
(28.43 KiB) Downloaded 321 times
Last edited by upani1982 on Tue Sep 13, 2011 10:51 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Increase Row Width and Wrap Text

Post by localghost »

Please get used to always providing a minimal example that is compilable out of the box*. This becomes essential especially when the problem is more complicated. People are rarely motivated to build an example just to test possible solutions for you. And finally it increases your chance for getting good answers almost instantly.

I'm pretty sure that you want to decrease the row width instead of increase. The below code reproduces the given table quite nice (with some enhancements).

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage[tableposition=top]{caption}
\usepackage{multirow,booktabs}
\usepackage{siunitx}

\begin{document}
  \begin{table}[!ht]
    \sisetup{table-number-alignment=right}   % Can also be placed in the preamble for global setting
    \caption{Add caption}\label{tab:addlabel}
    \centering
    \footnotesize
    \begin{tabular}{lS[table-figures-decimal=0]SSSS} \toprule
      &  & \multicolumn{2}{c}{Maximum Eigenvalue} & \multicolumn{2}{c}{Using Maximum Trace} \\ \cmidrule(lr){3-4}\cmidrule(lr){5-6}\addlinespace
      \multirow{2}{*}{Commodity}& \multirow{2}{*}{Lag Length} & {H0: Rank=0 Vs} & {H0: Rank=1 Vs} & {H0: Rank=0 Vs} & {H0: Rank=1 Vs} \\
                  &              & {H1: Rank=1}    & {H1: Rank=2}    & {H1: Rank=1}    & {H1: Rank=2}    \\ \midrule
      Gold        &           10 &            8.82 &            0.14 &            8.96 &            0.14 \\
      Silver      &            7 &            39.2 &            3.57 &           42.76 & 3.57 \\
      Aluminum    &            5 &           50.91 &             3.2 &           54.11 & 3.2 \\
      Copper      &           10 &          105.34 &            2.91 &          108.25 & 2.91 \\
      Lead        &           10 &           30.67 &            3.81 &           34.48 & 3.81 \\
      Nickel      &           10 &           26.48 &            5.43 &            31.9 & 5.43 \\
      Zinc        &            9 &           38.54 &            3.66 &           42.19 & 3.66 \\
      Crude Oil   &            9 &           21.55 &               4 &           25.55 & 4 \\
      Natural Gas &            4 &           9.66  &            2.51 &           12.17 & 2.51 \\ \bottomrule
    \end{tabular}%
  \end{table}%
\end{document}
The font size for the whole table has been decreased to make it fit the page. The content of the second row in the table head has simply been split into two rows. Note that the siunitx package has been use to align the numbers at the decimal marker as well as to the right inside the cells. Have a look at the package manual for details. Other enhancements should be self-explanatory. And also refer to the manuals of the other involved packages.

* This is not the first time that you need to be reminded in this regard.


Thorsten
upani1982
Posts: 43
Joined: Wed May 12, 2010 11:42 am

Re: Increase Row Width and Wrap Text

Post by upani1982 »

Hi Localghost,

Thanks a lot for your reply. I will take care of the issue you have highlighted in my future mails. I am extremely sorry for the mistake. When i run the code, i am getting an error expl3.sty not find. I am not able to understand, which package is this. I am using Mikitex 2.9 and winedt for the compilation.

Waiting for your reply.

With sincere regards,
Upananda
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Increase Row Width and Wrap Text

Post by localghost »

upani1982 wrote:[…] When i run the code, i am getting an error expl3.sty not find. I am not able to understand, which package is this. […]
The siunitx package relies on »expl3«, which is part of the l3kernel bundle. Install at least this by the MiKTeX Package Manager (MPM). Probably you have to synchronize the repository database before (see attachment).
Attachments
Synchronization of the repository database by the MiKTeX Package Manager (MPM).
Synchronization of the repository database by the MiKTeX Package Manager (MPM).
MPM(Admin)-Repository-Synchronize.png (45.05 KiB) Viewed 5582 times
upani1982
Posts: 43
Joined: Wed May 12, 2010 11:42 am

Re: Increase Row Width and Wrap Text

Post by upani1982 »

Hi Locaghost,

I am grateful to you for your suggestions. I am getting nice output. I am not able to understand the commands you have used. If you can explain, it would be great help. As i do not have much knowledge regarding the latex. I am learning each day from this great forum. I have a large number of tables to format. Your help will save me and will try on my own to format all the tables in the similar way.

With regards,
Upananda
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Increase Row Width and Wrap Text

Post by localghost »

Detailed explanations would go beyond the scope of a post. I recommend to take a look at the siunitx manual. It explains all commands and settings better than anybody else could ever do. Searching the manual for the commands I used won't take much time. Package manuals are the best source of information.
upani1982
Posts: 43
Joined: Wed May 12, 2010 11:42 am

Re: Increase Row Width and Wrap Text

Post by upani1982 »

Dear Localghost,

Please give me an example MWE. I will follow the format.

With regards,
Upananda
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Increase Row Width and Wrap Text

Post by localghost »

upani1982 wrote:[…] Please give me an example MWE. I will follow the format.[…]
I'm afraid I can't follow you. For what do you need another MWE? My solution from an earlier posts already represents such a MWE.
Post Reply