2

I am trying to create a table with tree subtables in it. To do so I have written the following code:

\documentclass[twoside]{article} 
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{sidecap}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{extramarks}
\usepackage{graphicx}
\usepackage{mathpazo}
\usepackage{amsmath}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{multicol}
\usepackage[toc,page]{appendix}
\usepackage{subcaption}

\begin{document} % <---
\begin{table}[h]
\begin{subtable}[b]{0.5\textwidth}
\centering
\begin{tabular}{ll|ll}
\multicolumn{2}{c|}{Consumo} & \multicolumn{2}{c}{Producción} \\ \hline
Metabolito      & Valor      & Metabolito       & Valor       \\ \hline
D-Fructosa      & 10,00      & CO\textsubscript{2}              & 22,81               
\\
Amonio          & 4,77       & H\textsubscript{2}O              & 29,18           
\\
Fosfato         & 3,21       & H\textsuperscript{+}               & 17,53       
\\
O\textsubscript{2}              & 22,00      & Acetato          & 0,0038      \\ \hline
\end{tabular}
\caption{\textit{E.coli} con fuente de carbono fructosa}\label{tabla4.1}
\end{subtable}
\begin{subtable}[b]{0.5\textwidth}
\centering
\begin{tabular}{ll|ll}
\multicolumn{2}{c|}{Consumo} & \multicolumn{2}{c}{Producción} \\ \hline
Metabolito      & Valor      & Metabolito       & Valor       \\ \hline
D-Fructosa      & 10,00      & CO\textsubscript{2}              & 22,81       \\
Amonio          & 4,77       & H\textsubscript{2}O              & 29,18       \\
Fosfato         & 3,21       & H\textsuperscript{+}               & 17,53       \\
O\textsubscript{2}              & 22,00      & Acetato          & 0,0038      \\ \hline
\end{tabular}
\caption{\textit{E.coli} con fuente de carbono fructosa}\label{tabla4.2}
\end{subtable}
\begin{subtable}[]{0.5\textwidth}
\vspace{15pt}\hspace{0.5\linewidth}\begin{tabular}{ll|ll}
\multicolumn{2}{c|}{Consumo} & \multicolumn{2}{c}{Producción} \\ \hline
Metabolito      & Valor      & Metabolito       & Valor       \\ \hline
D-Fructosa      & 10,00      & CO\textsubscript{2}              & 22,81       \\
Amonio          & 4,77       & H\textsubscript{2}O              & 29,18       \\
Fosfato         & 3,21       & H\textsuperscript{+}               & 17,53       \\
O\textsubscript{2}              & 22,00      & Acetato          & 0,0038      \\ \hline
\end{tabular} \caption{\textit{E.coli} con fuente de carbono fructosa}\label{tabla4.3}
\end{subtable}
\caption{Resultados de las distintas simulaciones}
\end{table}
\end{document}% <---

The problem is that the third subtable is not aligned with its caption:

enter image description here

Is there any easy solution to align them?

  • Yes. See the subcaption manual for options. Set alignment for all sub-figures or just sub-tables, as you wish. Never use h alone as a float specifier. Where is LaTeX meant to put it if it doesn't fit? h means 'here, if it fits'. Please make your code compilable. – cfr Dec 10 '17 at 2:32
  • remove \vspace{15pt}\hspace{0.5\linewidth} from third subtable. however each of your table is wider than 0.5\textwidth (in page layout as is in your code example), so equation overlap (if i test your code) or tables are in one column if test your code after considering aforementioned suggestion. also i take liberty and make your code compilable. – Zarko Dec 10 '17 at 8:27
2
  • your tables are wider than width of \subtable, consequently using your mwe (after adding missing parts of code, see my comment above) your tables overlaps (red lines on image below indicate your page layout):

enter image description here

  • considering my suggestion in comment above, you will obtain:

enter image description here

  • if i increase text width with use of the package geometry (using its default page layout settings) than i obtain after some small tweak of your subtable size, i obtain:

enter image description here

Edit: code, where is for chemical formulas used the mhchem package, for the last case is:

\documentclass[twoside]{article}
\usepackage{geometry} % <---
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{sidecap}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{extramarks}
\usepackage{graphicx}
\usepackage{mathpazo}
\usepackage{amsmath}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{multicol}
\usepackage[toc,page]{appendix}
\usepackage{subcaption}
\usepackage[version=4]{mhchem} % <--- new

%-------------------------------- show page layout, don't use in real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\begin{table}[ht]
\renewcommand\arraystretch{1.2}
\centering
\begin{subtable}{0.48\textwidth}
\centering
\begin{tabular}{ll|ll}
\multicolumn{2}{c|}{Consumo} & \multicolumn{2}{c}{Producción} \\ \hline
Metabolito      & Valor      & Metabolito       & Valor         \\ \hline
D-Fructosa      & 10,00      & \ce{CO2}         & 22,81         \\
Amonio          & 4,77       & \ce{H2O}         & 29,18         \\
Fosfato         & 3,21       & \ce{H+}          & 17,53         \\
\ce{O2}         & 22,00      & Acetato          & 0,0038        \\ \hline
\end{tabular}
\caption{\textit{E.coli} con fuente de carbono fructosa}\label{tabla4.1}
\end{subtable}
    \hfil
\begin{subtable}{0.48\textwidth}
\centering
\begin{tabular}{ll|ll}
\multicolumn{2}{c|}{Consumo} & \multicolumn{2}{c}{Producción} \\ \hline
Metabolito      & Valor      & Metabolito       & Valor         \\ \hline
D-Fructosa      & 10,00      & \ce{CO2}         & 22,81         \\
Amonio          & 4,77       & \ce{H2O}         & 29,18         \\
Fosfato         & 3,21       & \ce{H+}          & 17,53         \\
\ce{O2}         & 22,00      & Acetato          & 0,0038        \\ \hline
\end{tabular}
\caption{\textit{E.coli} con fuente de carbono fructosa}\label{tabla4.2}
\end{subtable}

\medskip
\begin{subtable}{0.48\textwidth}
\begin{tabular}{ll|ll}
\multicolumn{2}{c|}{Consumo} & \multicolumn{2}{c}{Producción} \\ \hline
Metabolito      & Valor      & Metabolito       & Valor         \\ \hline
D-Fructosa      & 10,00      & \ce{CO2}         & 22,81         \\
Amonio          & 4,77       & \ce{H2O}         & 29,18         \\
Fosfato         & 3,21       & \ce{H+}          & 17,53         \\
\ce{O2}         & 22,00      & Acetato          & 0,0038        \\ \hline
\end{tabular}
\caption{\textit{E.coli} con fuente de carbono fructosa}\label{tabla4.3}
\end{subtable}
\caption{Resultados de las distintas simulaciones}
\end{table}
\end{document}
|improve this answer|||||
  • Almost synchronized! The answers are a bit different, so I can leave mine :):):) – CarLaTeX Dec 10 '17 at 8:51
2

Putting an empty line before the last subtable and adding a \centering would do the trick.

Your MWE isn't complete, if I only add \begin{document} ... \end{document} the subtables overlap, I can't reproduce your output, and I get overfull hbox. Hence I changed it a bit:

  1. I've used the font \footnotesize
  2. I've removed the vertical space before the first column and after the last one
  3. I've used booktabs package for horizontal lines
  4. and dcolumn for the alignment of the numbers.

Here is the result:

enter image description here

And here is the code:

\documentclass[twoside]{article} 
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{array}
\usepackage{booktabs}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{,}{,}{#1}}
\usepackage{subcaption}
\captionsetup[sub]{font=footnotesize,labelfont={footnotesize}}

\begin{document}
\begin{table}[ht!]\footnotesize\centering
    \begin{subtable}{0.48\textwidth}
        \centering
        \begin{tabular}{@{}ld{2}ld{4}@{}}
            \toprule
            \multicolumn{2}{@{}c}{Consumo} & \multicolumn{2}{c@{}}{Producción}\\ 
            \cmidrule(r){1-2} \cmidrule(l){3-4}
            Metabolito & \multicolumn{1}{l}{Valor}      & Metabolito       & \multicolumn{1}{l@{}}{Valor}       \\ 
            \cmidrule(r){1-2} \cmidrule(l){3-4}
            D-Fructosa & 10,00      & CO\textsubscript{2} & 22,81\\
            Amonio & 4,77       & H\textsubscript{2}O & 29,18\\
            Fosfato & 3,21       & H\textsuperscript{+}& 17,53\\
            O\textsubscript{2} & 22,00   & Acetato          & 0,0038      \\
            \bottomrule
        \end{tabular}
        \caption{\textit{E.coli} con fuente de carbono fructosa}\label{tabla4.1}
    \end{subtable}
    \hfill
    \begin{subtable}{0.48\textwidth}
        \centering
        \begin{tabular}{@{}ld{2}ld{4}@{}}
            \toprule
            \multicolumn{2}{@{}c}{Consumo} & \multicolumn{2}{c@{}}{Producción} \\ 
            \cmidrule(r){1-2} \cmidrule(l){3-4}
            Metabolito      & \multicolumn{1}{l}{Valor}      & Metabolito       & \multicolumn{1}{l@{}}{Valor}       \\ 
            \cmidrule(r){1-2} \cmidrule(l){3-4}
            D-Fructosa      & 10,00      & CO\textsubscript{2}              & 22,81       \\
            Amonio          & 4,77       & H\textsubscript{2}O              & 29,18       \\
            Fosfato         & 3,21       & H\textsuperscript{+}               & 17,53       \\
            O\textsubscript{2}              & 22,00      & Acetato          & 0,0038      \\
            \bottomrule
        \end{tabular}
        \caption{\textit{E.coli} con fuente de carbono fructosa}\label{tabla4.2}
    \end{subtable}

    \vspace{\baselineskip}
    \begin{subtable}{0.48\textwidth}
        \begin{tabular}{@{}ld{2}ld{4}@{}}
            \toprule
            \multicolumn{2}{@{}c}{Consumo} & \multicolumn{2}{c@{}}{Producción} \\
            \cmidrule(r){1-2} \cmidrule(l){3-4}
            Metabolito      & \multicolumn{1}{l}{Valor}      & Metabolito       & \multicolumn{1}{l@{}}{Valor}       \\ 
            \cmidrule(r){1-2} \cmidrule(l){3-4}
            D-Fructosa      & 10,00      & CO\textsubscript{2}              & 22,81       \\
            Amonio          & 4,77       & H\textsubscript{2}O              & 29,18       \\
            Fosfato         & 3,21       & H\textsuperscript{+}               & 17,53       \\
            O\textsubscript{2}              & 22,00      & Acetato          & 0,0038      \\ 
            \bottomrule
        \end{tabular} 
        \caption{\textit{E.coli} con fuente de carbono fructosa}\label{tabla4.3}
    \end{subtable}
    \caption{Resultados de las distintas simulaciones}
\end{table}
\end{document}
|improve this answer|||||
  • 1
    nice answer (+1)! and distinct different from mine :-) – Zarko Dec 10 '17 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.