Graphics, Figures & TablesNice table without column

Information and discussion about graphics, figures & tables in LaTeX documents.
pallav
Posts: 170
Joined: Wed Nov 12, 2008 5:53 pm

Nice table without column

Post by pallav »

I took a table help from this forum (titled Table Column Width Adjustment). I want to put a mathematical to every cell of the table with a very nice look. I have tried with your tex but it gives error. Please help.

Code: Select all

\documentclass[11pt]{article}
\usepackage{caption}
\usepackage{booktabs,multirow,amsmath,amssymb}
\usepackage{siunitx}


\begin{document}
  \begin{table}[!ht]
    \caption{Markov channel parameter settings}
    \centering
    \label{tab:markovchapara}
    \begin{tabular}{    
      c
      S[table-format=1.2]
      @{~}
      S[table-format=1.2]
      S[table-format=1.3]
      @{~}
      S[table-format=1.3]
    }\toprule
      \multirow{2}{*}[-0.5ex]{Channel $j$} & \multicolumn{2}{c}{line1}  & \multicolumn{2}{c}{line2} \\ \cmidrule(r){2-3}\cmidrule(l){4-5}
        & {$p_j$} & {$q_j$} & {$\pi_{bj}$} & {$\pi_{ij}$} \\ \midrule
      1 & $\Phi(N(t))=\frac{\alpha N(t)}{K(t)}$       & 0.4     & $\Phi(N(t))=\frac{\alpha N(t)}{K(t)}$      & 0.8     \\
      2 & $\Phi(N(t))=\frac{\alpha N(t)}{K(t)}$     & 0.6     & $\Phi(N(t))=\frac{\alpha N(t)}{K(t)}$     & 0.75    \\
    \bottomrule
    \end{tabular}
  \end{table}
\end{document}
Last edited by pallav on Tue Aug 21, 2012 3:31 pm, 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
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Nice table without column

Post by cgnieder »

You need to enclose every cell in a S column into braces that is not a numerical input:

Code: Select all

\documentclass[11pt]{article}
\usepackage{caption}
\usepackage{booktabs,multirow,amsmath,amssymb}
\usepackage{siunitx}


\begin{document}
  \begin{table}[!ht]
    \caption{Markov channel parameter settings}
    \centering
    \label{tab:markovchapara}
    \begin{tabular}{
      c
      S[table-format=1.2]
      @{~}
      S[table-format=1.2]
      S[table-format=1.3]
      @{~}
      S[table-format=1.3]
    }\toprule
      \multirow{2}{*}[-0.5ex]{Channel $j$} & \multicolumn{2}{c}{line1}  & \multicolumn{2}{c}{line2} \\ \cmidrule(r){2-3}\cmidrule(l){4-5}
        & {$p_j$}                                     & {$q_j$} & {$\pi_{bj}$}                               & {$\pi_{ij}$} \\ \midrule
      1 & {$\Phi(N(t))=\frac{\alpha N(t)}{K(t)}$}     & 0.4     & {$\Phi(N(t))=\frac{\alpha N(t)}{K(t)}$}    & 0.8     \\
      2 & {$\Phi(N(t))=\frac{\alpha N(t)}{K(t)}$}     & 0.6     & {$\Phi(N(t))=\frac{\alpha N(t)}{K(t)}$}    & 0.75    \\
    \bottomrule
    \end{tabular}
  \end{table}
\end{document}
Since your columns 2 and 4 don't contain any numerical input at all but only maths you could also make them math columns:

Code: Select all

\documentclass[11pt]{article}
\usepackage{caption}
\usepackage{booktabs,multirow,amsmath,amssymb}
\usepackage{siunitx}


\begin{document}
  \begin{table}[!ht]
    \caption{Markov channel parameter settings}
    \centering
    \label{tab:markovchapara}
    \begin{tabular}{
      c
      >{$}c<{$}
      @{~}
      S[table-format=1.2]
      >{$}c<{$}
      @{~}
      S[table-format=1.3]
    }\toprule
      \multirow{2}{*}[-0.5ex]{Channel $j$} & \multicolumn{2}{c}{line1}  & \multicolumn{2}{c}{line2} \\ \cmidrule(r){2-3}\cmidrule(l){4-5}
        & p_j                                     & {$q_j$} & \pi_{bj}                               & {$\pi_{ij}$} \\ \midrule
      1 & \Phi(N(t))=\frac{\alpha N(t)}{K(t)}     & 0.4     & \Phi(N(t))=\frac{\alpha N(t)}{K(t)}    & 0.8     \\
      2 & \Phi(N(t))=\frac{\alpha N(t)}{K(t)}     & 0.6     & \Phi(N(t))=\frac{\alpha N(t)}{K(t)}    & 0.75    \\
    \bottomrule
    \end{tabular}
  \end{table}
\end{document}
Regards
site moderator & package author
pallav
Posts: 170
Joined: Wed Nov 12, 2008 5:53 pm

Re: Nice table without column

Post by pallav »

Thank you. Its works good. Would you please suggest me some other good looking style of table format specially used in thesis/books.
pallav
Posts: 170
Joined: Wed Nov 12, 2008 5:53 pm

Nice table without column

Post by pallav »

How to warp the text if the a sentence is long in such as

Code: Select all

\multicolumn{2}{c}{Markov channel parameter settings 1}

instead of

Code: Select all

\multicolumn{2}{c}{line1}
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Nice table without column

Post by cgnieder »

If I'm guessing right you want something like this:

Code: Select all

\documentclass[11pt]{article}
\usepackage{caption}
\usepackage{booktabs,multirow,amsmath,amssymb}
\usepackage{siunitx}


\begin{document}
  \begin{table}[!ht]
    \caption{Markov channel parameter settings}
    \centering
    \label{tab:markovchapara}
    \begin{tabular}{
      c
      >{$}c<{$}
      @{~}
      S[table-format=1.2]
      >{$}c<{$}
      @{~}
      S[table-format=1.3]
    }\toprule
      \multirow{2}{*}[-0.5ex]{Channel $j$} & \multicolumn{2}{p{9em}}{A long, long, long line, that is broken}  & \multicolumn{2}{c}{line2} \\ \cmidrule(r){2-3}\cmidrule(l){4-5}
        & p_j                                     & {$q_j$} & \pi_{bj}                               & {$\pi_{ij}$} \\ \midrule
      1 & \Phi(N(t))=\frac{\alpha N(t)}{K(t)}     & 0.4     & \Phi(N(t))=\frac{\alpha N(t)}{K(t)}    & 0.8     \\
      2 & \Phi(N(t))=\frac{\alpha N(t)}{K(t)}     & 0.6     & \Phi(N(t))=\frac{\alpha N(t)}{K(t)}    & 0.75    \\
    \bottomrule
    \end{tabular}
  \end{table}
\end{document}
Regards
site moderator & package author
pallav
Posts: 170
Joined: Wed Nov 12, 2008 5:53 pm

Re: Nice table without column

Post by pallav »

If I use the last, the table goes out from the page due to its long width. So I want to put the text wraped. Also if we use some long math expression, the same problem occurs. So I need to modify the code so the the long text/math expessions will come in two or more lines.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Nice table without column

Post by cgnieder »

Would you please add a Infominimal working example that shows what exactly goes wrong? Otherwise answering is more of a guessing than actually giving you good advice.

Regards
site moderator & package author
pallav
Posts: 170
Joined: Wed Nov 12, 2008 5:53 pm

Re: Nice table without column

Post by pallav »

I am writing you in brief what I exactly need with the help of a table. The style of the table looks like the upper table attached herewith and the cells to be filled up by mathematical expression/text as like the lower part of the table. Also I need the whole table in \scriptsize. Hope I am able to share about my problem.
Attachments
table.JPG
table.JPG (84.98 KiB) Viewed 6915 times
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Nice table without column

Post by cgnieder »

Is this a screenshot from one of your tables? Or is that how you want your table to look like? Either way, could you please add a Infominimal working example (i.e. some actual code), anyway, that shows what you mean by
the table goes out from the page due to its long width
Regards
site moderator & package author
pallav
Posts: 170
Joined: Wed Nov 12, 2008 5:53 pm

Nice table without column

Post by pallav »

Thank you for your help, I have made the whole table to script size. Thanks a lot again, it's really appreciated.

Would you please tell me how to increase the distance of two adjacent rows and two adjacent columns a little bit more?
Post Reply