Information and discussion about graphics, figures & tables in LaTeX documents.
erictamlam
Posts: 8 Joined: Sun Apr 29, 2012 7:41 am
Post
by erictamlam » Sun Apr 29, 2012 7:55 am
Hi all, I am a beginner writing papers in latex. I wanted to create a table like this, but my code didn't work out the way i wanted. Anyone lending a hand please? thanks!
Code: Select all
\begin{table}
\begin{tabular}{ccccc}
\hline
\multirow{2}{*}{Channel $j$} & \multicolumn{2}{c}{Transition prob.} & \multicolumn{2}{c}{Equilibrium distribution} \\ \cline{2-3} & $p_j$ & $q_j$ \multicolumn{2}{c}{} \\
%\multicolumn{1}{c}{}&\multicolumn{1}{c}{$p_j$}&\multicolumn{1}{c}{$q_j$}&\multicolumn{1}{c}{$\pi_{bj}$}&\multicolumn{1}{c}{$\pi_{ij}$}\\
\hline
1 & 0.1 & 0.4 & 0.2 & 0.8 \\
2 & 0.2 & 0.6 & 0.25 & 0.75\\
3 & 0.3 & 0.7 & 0.3 & 0.7\\
4 & 0.3 & 0.5 &0.375 & 0.625\\
5 & 0.35 & 0.65 & 0.35 & 0.65\\
6 & 0.4 & 0.6 & 0.4 & 0.6 \\
7 & 0.6 & 0.6 &0.5 & 0.5\\
8 & 0.6 & 0.4 & 0.6 & 0.4 \\
\hline
\end{tabular}
\label{tab:markovchapara}
\end{table}
Attachments
The way I wanted the table to be like. QQ截图20120429133812.jpg (25.14 KiB) Viewed 2244 times
Last edited by
localghost on Sun Apr 29, 2012 10:42 am, edited 1 time in total.
NEW: TikZ book now 40% off at Amazon.com for a short time.
localghost
Site Moderator
Posts: 9202 Joined: Fri Feb 02, 2007 12:06 pm
Post
by localghost » Sun Apr 29, 2012 11:22 am
You should provide a standalone
minimal example that allows testing solutions instantly. People are rarely motivated to
find out all necessary stuff themselves.
For a deeper understanding of the below code please take a look at the respective manuals of the involved packages.
Code: Select all
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[tableposition=top]{caption}
\usepackage{booktabs,multirow}
\usepackage{siunitx}
\begin{document}
\begin{table}[!ht]
\caption{Table caption}
\label{tab:markovchapara}
\centering
\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}{Transition prob.} & \multicolumn{2}{c}{Equilibrium distr.} \\ \cmidrule(lr){2-3} \cmidrule(lr){4-5}
& {$p_j$} & {$q_j$} & {$r_j$} & {$s_j$} \\ \midrule
1 & 0.1 & 0.4 & 0.2 & 0.8 \\
2 & 0.2 & 0.6 & 0.25 & 0.75 \\
3 & 0.3 & 0.7 & 0.3 & 0.7 \\
4 & 0.3 & 0.5 & 0.375 & 0.625 \\
5 & 0.35 & 0.65 & 0.35 & 0.65 \\
6 & 0.4 & 0.6 & 0.4 & 0.6 \\
7 & 0.6 & 0.6 & 0.5 & 0.5 \\
8 & 0.6 & 0.4 & 0.6 & 0.4 \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
The
siunitx package is very good for alignment of numbers in table cells.
Best regards and welcome to the board
Thorsten
erictamlam
Posts: 8 Joined: Sun Apr 29, 2012 7:41 am
Post
by erictamlam » Sun Apr 29, 2012 12:19 pm
thanks for the reply! it worked, but how to make sure that 'p' and 'q' split the column width of 'transition probability' equally? Thanks
localghost wrote: You should provide a standalone
minimal example that allows testing solutions instantly. People are rarely motivated to
find out all necessary stuff themselves.
For a deeper understanding of the below code please take a look at the respective manuals of the involved packages.
Code: Select all
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[tableposition=top]{caption}
\usepackage{booktabs,multirow}
\usepackage{siunitx}
\begin{document}
\begin{table}[!ht]
\caption{Table caption}
\label{tab:markovchapara}
\centering
\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}{Transition prob.} & \multicolumn{2}{c}{Equilibrium distr.} \\ \cmidrule(lr){2-3} \cmidrule(lr){4-5}
& {$p_j$} & {$q_j$} & {$r_j$} & {$s_j$} \\ \midrule
1 & 0.1 & 0.4 & 0.2 & 0.8 \\
2 & 0.2 & 0.6 & 0.25 & 0.75 \\
3 & 0.3 & 0.7 & 0.3 & 0.7 \\
4 & 0.3 & 0.5 & 0.375 & 0.625 \\
5 & 0.35 & 0.65 & 0.35 & 0.65 \\
6 & 0.4 & 0.6 & 0.4 & 0.6 \\
7 & 0.6 & 0.6 & 0.5 & 0.5 \\
8 & 0.6 & 0.4 & 0.6 & 0.4 \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
The
siunitx package is very good for alignment of numbers in table cells.
Best regards and welcome to the board
Thorsten