I've been fiddling with the following table for a while, and have some minor issues.
\documentclass{article}
\usepackage{threeparttable}
\usepackage{multirow}
\begin{document}
\begin{table}[!ht]
\caption{
\textbf{Pheno file format}}
\begin{threeparttable}
\begin{tabular}{|l|l|c|}\hline\hline
\textbf{Pheno file headers} & \multicolumn{2}{|c|}{\textbf{Notes}} \\ \hline\hline
sex & \multicolumn{2}{|l|}{The sex column is restricted to the following values.} \\ \hline\hline
& \multicolumn{1}{|l|}{Sex} & \multicolumn{1}{p{1cm}|}{Value} \\ \hline\hline
& Male & \multicolumn{1}{p{1cm}|}{1} \\ \hline
& \multicolumn{1}{|l|}{Female} & \multicolumn{1}{p{1cm}|}{2} \\ \hline
& \multicolumn{1}{|l|}{Missing}& \multicolumn{1}{|p{1cm}|}{-1} \\ \hline
studyid & \multicolumn{2}{|l|}{\multirow{1}{*}{Description of the study the data belongs to - eg. 'Hapmap6.0'.}} \\
& \multicolumn{2}{|l|}{If studyid is not given, 'unknown' is used.} \\ \hline
studyid & \multicolumn{2}{p{\dimexpr\textwidth-2\tabcolsep\relax}|}{Description of the study the data belongs to - eg. 'Hapmap6.0'.
If studyid is not given, 'unknown' is used.} \\ \hline
%\cline{3-4}
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}
Questions:
-
So, I'm sort of embedding a subtable inside a table. I first had
it as a separate table, but then I stuck it inside the main table.
It is the table with headersSex
andValue
. It would be nice if
I could adjust the width of the third margin so that it was only as
wide as necessary, and also if all the lines to the left of that
table, starting with the double line underSex/Value
were not
present. The other problem is that the numbers in the third column
are not left justified. So I'd like it to look something like----------------------------------------------------------------------------- | Pheno file headers | Notes | ============================================================================== | sex | The sex column is restricted to the following values | ============================================================================== | Sex | Value | | Male | 1 | | Female | 2 | | Missing| -1 | ------------------------------------------------------------------------------ | Studyid | Some stuff | ------------------------------------------------------------------------------
Can this be done without lots of complexity?
-
I've got two examples of a cell (starting with studyid) across two rows and two columns. I think I prefer the one at the bottom. Is that the best way to do it? It certainly seems simpler than the one above it.
Best Answer
Perhaps a suggestion, but here is an alternative to your current set up. I've used
tabularx
to allow for variable-widthtabular
columns (via column typeX
), filling up to some fixed with using thetabularx
environment. Additionally,booktabs
provide a cleaner spread of tables vertically, while virtually restricting the use of vertical rules (due to the rule definitions). Either way, the tabular layout helps columnar alignment, which removes the requirement for using vertical rules anyway.The interior
tabular
has been adjusted to provide a natural-width horizontal alignment, as suggested in your ASCII-art interpretation.Using
\phantom{-}
leaves the correct amount of horizontal (and vertical) space for-
without actually typesetting it. That allows for aligning the entries within the nestedtabular
while also centering it.\jot
is a length of3pt
. Using it together with\\
, as in\\[\jot]
, pushes thetabular
line break down vertically by3pt
. Using a length register (like\jot
) is preferred over explicitly using\\[3pt]
, since you can modify\jot
(using, say\setlength{\jot}{5pt}
) in one location and it would take effect wherever it is used after the redefinition, rather than having to manually modify the3pt
vertical skip everywhere.Layout changes to the nested/interior
tabular
is possible (for example, if you want it horizontally centered within the outertabularx
, although the existing alignment seems sufficient).Finally, there's no need to use
multirow
anymore, more obvious reasons. In my opinion, the input code is simpler and easier to follow.