Graphics, Figures & Tables ⇒ Define a Table using ctable and tabularx
Define a Table using ctable and tabularx
I need to define a table that imitable the one in figure table.eps. The table must be 50 mm width (column width also controlled according to the drawing), numbers must be aligned by the dot, and the titles must be centered. I'm trying to do it using packages ctable and tabularx. The code I already developed is the following:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ctable[caption = Long title,
cap = Short title,
width = 50mm,
pos = btp,
label = tab:short]
{r@{}l r@{}l r@{}l}
{>{\hsize=0.5\hsize}X>{\hsize=0.5\hsize}X>{\hsize=2.0\hsize}X}
{
\tnote[\star]{Note 1}
\tnote[\dagger]{Note 2}
\tnote[\ddager]{Note 3}
}
{
\FL
\multicolumn{2}{c}{\textbf{Title 1}} & \multicolumn{2}{c}{\textbf{Title 2}} & \multicolumn{2}{c}{\textbf{Title 3}}\tmark[\star]
\ML
0&.0 & 0&.0 & 0&.0\tmark[\dagger]\NN
0&.0 & 0&.0 & 0&.0\tmark[\ddagger]\LL
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Unfortunately this code contains errors that I'm being unable to overcome. Can anyone assist me on this?
Best regards
Nuno Araújo
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
-
- Posts: 87
- Joined: Tue Sep 14, 2010 6:58 pm
Re: Define a Table using ctable and tabularx
Define a Table using ctable and tabularx
\documentclass[a4paper,twoside,twocolumn,openright]{book}
\usepackage[portuges,UKenglish]{babel}
\usepackage{fontenc}
\usepackage{pstricks}
\usepackage{epsfig}
\usepackage[latin9]{inputenc}
\usepackage{ucs}
\usepackage{makeidx}
\usepackage{hyperref}
\usepackage{fancyhdr}
\usepackage{natbib}
\usepackage{indentfirst}
\usepackage[caption=false]{subfig}
\usepackage{amssymb,amsmath,amsthm}
\usepackage{nextpage}
\usepackage{tocbibind}
\usepackage[Sonny]{fncychap}
\usepackage{epigraph}
\usepackage{ctable}
\usepackage{tabularx}
Regarding the use of \star, \dagger and \ddagger, I clearly forgot to put it in math mode. Thank for the warning.
Regarding the remaining errors, when I remove the code to control column width {>{\hsize=0.5\hsize}X>{\hsize=0.5\hsize}X>{\hsize=2.0\hsize}X} and \multicolumn{2}{c}{\textbf{Title 1,2 and 3}}, the code works perfectly. But, if possible, I would like to use them. Is it possible?
Best regards
Nuno
-
- Posts: 87
- Joined: Tue Sep 14, 2010 6:58 pm
Re: Define a Table using ctable and tabularx
A MWE is a "minimal working example" which lets others copy and test the code so they don't have to come up with a test document themselves.
Define a Table using ctable and tabularx
Regards
Nuno
Code: Select all
\documentclass[a4paper,twoside,twocolumn,openright]{book}
\usepackage{ctable}
\usepackage{tabularx}
\setlength{\columnwidth}{50mm}
\begin{document}
\ctable[caption = Long title,
cap = Short title,
width = 50mm,
pos = btp,
label = tab:short]
{r@{}l r@{}l r@{}l}
{>{\hsize=0.5\hsize}X>{\hsize=0.5\hsize}X>{\hsize=2.0\hsize}X}
{
\tnote[$\star$]{Note 1}
\tnote[$\dagger$]{Note 2}
\tnote[$\ddagger$]{Note 3}
}
{
\FL
\multicolumn{2}{c}{\textbf{Title 1}} & \multicolumn{2}{c}{\textbf{Title 2}} & \multicolumn{2}{c}{\textbf{Title 3}}\tmark[$\star$]
\ML
0&.0 & 0&.0 & 0&.0\tmark[$\dagger$]\NN
0&.0 & 0&.0 & 0&.0\tmark[$\ddagger$]\LL
}
\end{document}
-
- Posts: 87
- Joined: Tue Sep 14, 2010 6:58 pm
Define a Table using ctable and tabularx
Code: Select all
%{>{\hsize=0.5\hsize}X>{\hsize=0.5\hsize}X>{\hsize=2.0\hsize}X}
Re: Define a Table using ctable and tabularx
- Attachments
-
- table.png (26.46 KiB) Viewed 7556 times
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Define a Table using ctable and tabularx
Code: Select all
\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\begin{document}
\newlength{\testwidth}
\settowidth{\testwidth}{Title 1}
Width of ``Title 1'' (in pt): \the\testwidth
\setlength{\testwidth}{8.33333mm}
Width of 8.3\ldots mm (in pt): \the\testwidth
\end{document}
So you have to clarify whether a decrease of the font size in the table is an option or if the presented content is the one you will have in the actual table. We can do the rest later. However, the example below seems to be at least a partial solution.
Code: Select all
\documentclass[a4paper,twoside,twocolumn,openright]{book}
\usepackage{ctable}
\usepackage{tabularx}
\setlength{\columnwidth}{50mm}
\begin{document}
\ctable[%
caption = Long title,
cap = Short title,
doinside = \footnotesize,
width = 50mm,
pos = btp,
label = tab:short
]
{>{\hsize=0.5\hsize}X>{\hsize=0.5\hsize}X>{\hsize=2.0\hsize}X}
{
\tnote[$\star$]{Note 1}
\tnote[$\dagger$]{Note 2}
\tnote[$\ddagger$]{Note 3}
}
{
\FL
\multicolumn{1}{c}{\textbf{Title 1}} & \multicolumn{1}{c}{\textbf{Title 2}} & \multicolumn{1}{c}{\textbf{Title 3}}\tmark[$\star$]
\ML
0.0 & 0.0 & 0.0\tmark[$\dagger$]\NN
0.00 & 0.00 & 0.00\tmark[$\ddagger$]\LL
}
\end{document}
Best regards and welcome to the board
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Define a Table using ctable and tabularx
Regarding my column widths, given values are just an example. But what you have point me out explain the reason why a bad box was being reported! In the code bellow I changed the relations between the columns widths to overcome the problem you reported.
What I wish is to control the width of the columns (without changing font size) to manage the look of the tables in my documents. The titles should be center on the column but the numeric data aligned by the dot (with the dot centered on the Title above). I don´t know if it is possible.
Thank you for any comment on this.
Code: Select all
\documentclass[a4paper,twoside,twocolumn,openright]{book}
\usepackage{ctable}
\usepackage{tabularx}
\setlength{\columnwidth}{50mm}
\begin{document}
\ctable[%
caption = Long title,
cap = Short title,
doinside = \footnotesize,
width = 50mm,
pos = btp,
label = tab:short
]
{>{\hsize=0.9\hsize}X>{\hsize=0.9\hsize}X>{\hsize=1.2\hsize}X}
{
\tnote[$\star$]{Note 1}
\tnote[$\dagger$]{Note 2}
\tnote[$\ddagger$]{Note 3}
}
{
\FL
\multicolumn{1}{c}{\textbf{Title 1}} & \multicolumn{1}{c}{\textbf{Title 2}} & \multicolumn{1}{c}{\textbf{Title 3}}\tmark[$\star$]
\ML
1.004 & 0.0 & 0.0\tmark[$\dagger$]\NN
12.05 & 0.00 & 0.00\tmark[$\ddagger$]\LL
}
\end{document}
Define a Table using ctable and tabularx
I found the solution to the problem in a document publish by Lapo Filippo Mori, entitle Tables in LATEX2e: Packages and Methods. I just need to use the command \makebox[width][alignment]{text}. Please find below my final solution.
Best regards
Nuno Araújo
Code: Select all
\documentclass[a4paper,twoside,twocolumn,openright]{book}
\begin{document}
\begin{table}
\begin{center}
\caption[Short title]{Long title}
\begin{tabular}{r@{}l r@{}l r@{}l}
\\[-1mm]
\hline\\[-2mm]
\multicolumn{2}{c}{\makebox[15mm][c]{\textbf{Title 1}}} &
\multicolumn{2}{c}{\makebox[15mm][c]{\textbf{Title 2}}} &
\multicolumn{2}{c}{\makebox[20mm][c]{\textbf{Title 3}$^\star$}}\\
\\[-2mm]
\hline\\[-2mm]
\makebox[7.5mm][r]{1}& .12 &
\makebox[7.5mm][r]{0} & .0 &
\makebox[10mm][r]{34} & .12$^\dagger$\\
17&.3 & 123&.1 & 1&.003$^\ddagger$\\
\\[-2mm]
\hline\\[-2mm]
\multicolumn{6}{l}{$^\star$ \footnotesize{Note 1}}\\
\multicolumn{6}{l}{$^\dagger$ \footnotesize{Note 2}}\\
\multicolumn{6}{l}{$^\ddagger$ \footnotesize{Note 3}}\\
\end{tabular}
\end{center}
\end{table}
\end{document}