2

So I was making two tables and was having issues with the formatting. So how you give spaces in these table and how to align that 1st table with the caption on side?

1st Table

2nd Table

    \begin{table}[]
\caption{DNA Encoding and Decoding Rule}
\label{tab:my-table}
\setlength{\tabcolsep}{0.5em} % for the horizontal padding
{\renewcommand{\arraystretch}{1.2}% for the vertical padding
\begin{tabular}{@{}lllll@{}}
\toprule
       & 00 & 10 & 01 & 11 \\ \midrule
Rule 1 & A  & C  & G  & T  \\
Rule 2 & A  & G  & C  & T  \\
Rule 3 & T  & G  & C  & A  \\
Rule 4 & T  & C  & G  & A  \\
Rule 5 & G  & A  & T  & C  \\
Rule 6 & G  & T  & A  & C  \\
Rule 7 & C  & A  & T  & G  \\
Rule 8 & C  & T  & A  & G  \\ \bottomrule
\end{tabular}
}
\end{table}



 \begin{table}[]
\caption{Mutation effect example}
\label{tab:my-table}
\resizebox{\columnwidth}{!}{%
\begin{tabular}{@{}lllll@{}}
\toprule
\begin{tabular}[c]{@{}l@{}}Original \\    \\ Number\end{tabular} & DNA sequence & Type of mutation & Mutated sequence & Number corresponding to mutated sequence \\ \midrule
237 & ‘TCTG’ & Deletion     & ‘TTG’   & 61  \\ \midrule
237 & ‘TCTG’ & Insertion    & ‘TCATG’ & 909 \\
237 & ‘TCTG’ & Substitution & ‘TCAG’  & 225 \\
237 & ‘TCTG’ & Duplication  & ‘TCTTG’ & 957
\end{tabular}%
}
\end{table}
1
  • The package hvfloat by Herbert Voß provides the ability to put a caption to the side, along with many other possibilities. See the package documentation and/or the TUGboat article that describes it. May 22 at 23:52

3 Answers 3

3

I removed the padding in the first tabular and put the caption in the remaining space. I figure you already have the \captionsetup, so there was no point trying to reproduce it.

For the second table the main problem was trying to fit the last column on the page, and using as few rows as possible. I used tabularx, but only for the last column.

\documentclass{article}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{showframe}% alignment tool
\begin{document}

\begin{table}[]
\sbox0{% measure width
\begin{tabular}[t]{@{}lllll@{}}
\toprule
       & 00 & 10 & 01 & 11 \\ \midrule
Rule 1 & A  & C  & G  & T  \\
Rule 2 & A  & G  & C  & T  \\
Rule 3 & T  & G  & C  & A  \\
Rule 4 & T  & C  & G  & A  \\
Rule 5 & G  & A  & T  & C  \\
Rule 6 & G  & T  & A  & C  \\
Rule 7 & C  & A  & T  & G  \\
Rule 8 & C  & T  & A  & G  \\ \bottomrule
\end{tabular}}%
\begin{minipage}[t]{\dimexpr \columnwidth-\wd0-\columnsep}
\abovecaptionskip=0pt
\caption{DNA Encoding and Decoding Rule}
\label{tab:my-table}
\end{minipage}\hfill\usebox0
\end{table} 

\begin{table}[]
\caption{Mutation effect example}
\label{tab:my-table}
\begin{tabularx}{\columnwidth}{@{}llllX@{}}
\toprule
\parbox[t]{4em}{Original Number} &
\parbox[t]{4em}{DNA\newline sequence} &
\parbox[t]{4em}{Type of mutation} &
\parbox[t]{4em}{Mutated sequence} &
Number corresponding to mutated sequence \\ \midrule
237 & ‘TCTG’ & Deletion     & ‘TTG’   & 61  \\ \midrule
237 & ‘TCTG’ & Insertion    & ‘TCATG’ & 909 \\
237 & ‘TCTG’ & Substitution & ‘TCAG’  & 225 \\
237 & ‘TCTG’ & Duplication  & ‘TCTTG’ & 957
\end{tabularx}%
\end{table}

\vfill\hrule% to avoid becoming [p] floats.
\end{document}
0

how about this? I made some minimal example and cleaned up some stuff that was unclear to me. Remarks:

  • Notice two things:\begin{tabularx}{0.9\textwidth}{XXX}
  1. \begin{tabularx}{0.9\textwidth} defines the table to be 90% of textwidth, you can play around with this for your liking
  2. According to this post use e.g. XXX to have three evenly distributed column width accross your entire tablular width
  • I used tabularx-package.
  • I made some good experience with \hline to get horizontal lines
  • No Idea about the left-sided caption

Minimal Example:

\documentclass{article}
\usepackage{array}
\usepackage{tabularx}    
    
\begin{document}
\begin{table}[]
\caption{DNA Encoding and Decoding Rule}
\label{tab:my-table}
\begin{tabularx}{0.9\textwidth}{l X X X X }
\hline
       & 00 & 10 & 01 & 11 \\ \hline
Rule 1 & A  & C  & G  & T  \\
Rule 2 & A  & G  & C  & T  \\
Rule 3 & T  & G  & C  & A  \\
Rule 4 & T  & C  & G  & A  \\
Rule 5 & G  & A  & T  & C  \\
Rule 6 & G  & T  & A  & C  \\
Rule 7 & C  & A  & T  & G  \\
Rule 8 & C  & T  & A  & G  \\ \hline
\end{tabularx}
\end{table}



\begin{table}[]
\caption{Mutation effect example}
\label{tab:my-table}
\begin{tabularx}{0.9\textwidth}{XXXXX}
\hline
Original Number & DNA sequence & Type of mutation & Mutated sequence & Number corresponding to mutated sequence \\ \hline
237 & ‘TCTG’ & Deletion     & ‘TTG’   & 61  \\ 
237 & ‘TCTG’ & Insertion    & ‘TCATG’ & 909 \\
237 & ‘TCTG’ & Substitution & ‘TCAG’  & 225 \\
237 & ‘TCTG’ & Duplication  & ‘TCTTG’ & 957
\end{tabularx}
\end{table}
    
\end{document}

Looks like this:

enter image description here

0

Here are some ideas to achieve your output for each table:

  1. Set the \caption inside a minipage of desired width; this boxes it, allowing you to place it next to another "box" (like a tabular).

  2. Spacing between columns can be achieved using a tabularx "spread," or a predetermined @{<space>} column separation.

  3. makecell also helps with manual line-breaking in cells, as well as alignment specification that is cell-specific.

enter image description here

\documentclass{article}

\usepackage[margin=1in]{geometry}% Just for this example
\usepackage{booktabs,caption,tabularx,makecell}

\captionsetup[table]{%
  labelfont=bf,
  justification=raggedright,
  singlelinecheck=false
}

\begin{document}

\begin{table}
  \begin{minipage}[t]{.3\linewidth}
    \caption{DNA encoding and decoding Rule}
  \end{minipage}%
  \hfill
  \begin{tabular}[t]{ @{} l *{4}{ @{\hspace{4em}} c } @{} }
    \toprule
           & 00 & 10 & 01 & 11 \\
    \midrule
    Rule 1 &  A &  C &  G &  T \\
    Rule 2 &  A &  G &  C &  T \\
    Rule 3 &  T &  G &  C &  A \\
    Rule 4 &  T &  C &  G &  A \\
    Rule 5 &  G &  A &  T &  C \\
    Rule 6 &  G &  T &  A &  C \\
    Rule 7 &  C &  A &  T &  G \\
    Rule 8 &  C &  T &  A &  G \\
    \bottomrule
  \end{tabular}

  \bigskip

  \caption{Mutation effect example}
  \begin{tabularx}{\columnwidth}{@{} l @{\qquad} *{4}{X} @{}}
    \toprule
    \makecell[t]{Original \\ Number} &
    DNA sequence &
    Type of mutation &
    Mutated sequence &
    \raggedright\arraybackslash Number corresponding to mutated sequence \\
    \midrule
    237 & `TCTG' & Deletion     & `TTG'   & 61  \\
    237 & `TCTG' & Insertion    & `TCATG' & 909 \\
    237 & `TCTG' & Substitution & `TCAG'  & 225 \\
    237 & `TCTG' & Duplication  & `TCTTG' & 957 \\
    \bottomrule
  \end{tabularx}
\end{table}

\end{document}

For more spacing-related ideas in tables, see Column and row padding in tables.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .