3

This question already has an answer here:

I just want a section title and an adjustbox with a table below. The fact is that they exchange their placement, i.e. the table appears above.

I tried some command like an hypothetical halign? instead of center written in \begin{adjustbox}, but I couldn't get any solution.

Maybe it exists some equivalence to [H] used in tables.

Any suggestion?

\documentclass[12pt]{article}
\renewcommand{\baselinestretch}{1.5}
\usepackage[utf8]{inputenc}
\usepackage[catalan]{babel}

\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{adjustbox}

\begin{document}

\section{Taules}

\begin{adjustbox}{center, captionbelow={Cerca d'avaries I.}, float=table}

\begin{tabular}{|l|l|l|}
\hline
\rowcolor[HTML]{FFFC9E} 
\multicolumn{1}{|c|}{\cellcolor[HTML]{FFFC9E}\textbf{Incidents}}                                                    & \multicolumn{1}{c|}{\cellcolor[HTML]{FFFC9E}\textbf{Causes possibles}}                                                                      & \multicolumn{1}{c|}{\cellcolor[HTML]{FFFC9E}\textbf{Verificacions}}                                                                \\ \hline
                                                                                                                    & La xarxa no està sota tensió.                                                                                                               & \begin{tabular}[c]{@{}l@{}}Verificar la tensió en els\\ comandaments.\end{tabular}                                                 \\ \cline{2-3} 
\multirow{-2}{*}{El motor no arranca en el buit.}                                                                   & El circuit induït està tallat.                                                                                                              & \begin{tabular}[c]{@{}l@{}}Comprovar el circuit induït i\\ el reòstat d'arrencada.\end{tabular}                                    \\ \hline
\begin{tabular}[c]{@{}l@{}}El motor s'engega en el buit\\ i s'embala.\end{tabular}                                  & El circuit inductor està tallat.                                                                                                            & \begin{tabular}[c]{@{}l@{}}Comprovar el circuit inductor\\ i el reòstat de camp.\end{tabular}                                      \\ \hline
\begin{tabular}[c]{@{}l@{}}El motor s'engega, però es\\ cala.\end{tabular}                                          & \begin{tabular}[c]{@{}l@{}}Error de muntatge: el born comú,\\ induït-inductor, està unit al reòstat\\ en comptes de la xarxa.\end{tabular}  & \begin{tabular}[c]{@{}l@{}}Un fil de la xarxa ha d'anar\\ directament al born comú.\end{tabular}                                   \\ \hline
\begin{tabular}[c]{@{}l@{}}El motor s'engega amb poca\\ càrrega i s'embala.\end{tabular}                            & \begin{tabular}[c]{@{}l@{}}Error de muntatge: el born induït-\\ inductor està unital reòstat i no a\\ la xarxa.\end{tabular}                & \begin{tabular}[c]{@{}l@{}}Un fil de la xarxa ha d'anar\\ directament al born comú.\end{tabular}                                   \\ \hline
\begin{tabular}[c]{@{}l@{}}El motor s'engega massa\\ lentament.\end{tabular}                                        & Falta d'excitació.                                                                                                                          & \begin{tabular}[c]{@{}l@{}}S'ha d'engegar sempre amb el\\ reòstat de camp al zero.\end{tabular}                                    \\ \hline
\end{tabular}

\end{adjustbox}

\end{document}

enter image description here

marked as duplicate by Stefan Pinnow, Kurt, Zarko, TeXnician, barbara beeton Aug 30 '17 at 14:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

Use one of the following options instead of float=table:

  • nofloat=table: This will put the contents of adjustbox directly below the section without any attempts to change the positioning.
  • table=hb (or equivalently float={table}[hb]: This will first try to put the adjustbox at that place, put if there is not enough space left on the page, it will look for a place at the bottom of a page to put it.
\documentclass[12pt]{article}
\renewcommand{\baselinestretch}{1.5}
\usepackage[utf8]{inputenc}
\usepackage[catalan]{babel}

\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{adjustbox}

\begin{document}

\section{Taules}

\begin{adjustbox}{center, captionbelow={Cerca d'avaries I.}, nofloat=table}

\begin{tabular}{|l|l|l|}
\hline
\rowcolor[HTML]{FFFC9E} 
\multicolumn{1}{|c|}{\cellcolor[HTML]{FFFC9E}\textbf{Incidents}}                                                    & \multicolumn{1}{c|}{\cellcolor[HTML]{FFFC9E}\textbf{Causes possibles}}                                                                      & \multicolumn{1}{c|}{\cellcolor[HTML]{FFFC9E}\textbf{Verificacions}}                                                                \\ \hline
                                                                                                                    & La xarxa no està sota tensió.                                                                                                               & \begin{tabular}[c]{@{}l@{}}Verificar la tensió en els\\ comandaments.\end{tabular}                                                 \\ \cline{2-3} 
\multirow{-2}{*}{El motor no arranca en el buit.}                                                                   & El circuit induït està tallat.                                                                                                              & \begin{tabular}[c]{@{}l@{}}Comprovar el circuit induït i\\ el reòstat d'arrencada.\end{tabular}                                    \\ \hline
\begin{tabular}[c]{@{}l@{}}El motor s'engega en el buit\\ i s'embala.\end{tabular}                                  & El circuit inductor està tallat.                                                                                                            & \begin{tabular}[c]{@{}l@{}}Comprovar el circuit inductor\\ i el reòstat de camp.\end{tabular}                                      \\ \hline
\begin{tabular}[c]{@{}l@{}}El motor s'engega, però es\\ cala.\end{tabular}                                          & \begin{tabular}[c]{@{}l@{}}Error de muntatge: el born comú,\\ induït-inductor, està unit al reòstat\\ en comptes de la xarxa.\end{tabular}  & \begin{tabular}[c]{@{}l@{}}Un fil de la xarxa ha d'anar\\ directament al born comú.\end{tabular}                                   \\ \hline
\begin{tabular}[c]{@{}l@{}}El motor s'engega amb poca\\ càrrega i s'embala.\end{tabular}                            & \begin{tabular}[c]{@{}l@{}}Error de muntatge: el born induït-\\ inductor està unital reòstat i no a\\ la xarxa.\end{tabular}                & \begin{tabular}[c]{@{}l@{}}Un fil de la xarxa ha d'anar\\ directament al born comú.\end{tabular}                                   \\ \hline
\begin{tabular}[c]{@{}l@{}}El motor s'engega massa\\ lentament.\end{tabular}                                        & Falta d'excitació.                                                                                                                          & \begin{tabular}[c]{@{}l@{}}S'ha d'engegar sempre amb el\\ reòstat de camp al zero.\end{tabular}                                    \\ \hline
\end{tabular}

\end{adjustbox}

\end{document}

enter image description here

  • You're welcome. If this solves your problem, please mark this answer as "Accepted" (by clicking the checkmark sign left of it). – Tiuri Aug 30 '17 at 12:19
  • 1
    Another option would be to retain the float and use the positioning key 'table=hb' to place the table here or bottom of the page. You might get a bad page break if you eliminate the float. – Ross Aug 30 '17 at 12:30
0

i would rather change a way as this table is designed:

  • not use adjustbox for shrink table to text width (it also reduce used font size, which can become unreadable small), instead it is better to use float table with proper set of table
  • use tabularx for table environment with prescribed width of text width and by it fit table to text width
  • use of a tabularx column type X enable remove all clutter of nested tabular tables and manually breaking long texts in cells. this is now done automatically
  • define new column type which enable "smart" break and hyphenation of texts in cells.

considering above gives concise and clear code for (to my opinion) better looking your table:

\documentclass[12pt]{article}
\renewcommand{\baselinestretch}{1.5}
\usepackage[utf8]{inputenc}
\usepackage[catalan]{babel}

\usepackage[table,xcdraw]{xcolor}
\usepackage{ragged2e}
\usepackage{makecell, tabularx}           % new
\renewcommand\theadfont{\bfseries\small}  % for column headers font
\newcolumntype{L}{>{\RaggedRight}X}       % new column type which enable
                                          % "smart" ragged text on the 
                                          % right side of multi line text
                                          % in cells
%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

\section{Taules}

\begin{table}[ht]
\small                   % smaller font, for better fit text in cells
\begin{tabularx}{\linewidth}{|L|L|L|}
    \hline
\rowcolor[HTML]{FFFC9E}  % sufficient for coloring of the first row
\thead{Incidents}   & \thead{Causes possibles} & \thead{Verificacions}  \\
    \hline
El motor no arranca en el buit.
    &   El circuit induït està tallat.
        &   Comprovar el circuit induït i el reòstat d'arrencada.       \\
    \hline
El motor s'engega en el buit i s'embala.
    &   El circuit inductor està tallat.
        &   Comprovar el circuit inductor i el reòstat de camp.         \\
    \hline
El motor s'engega, però es cala.
    &   Error de muntatge: el born comú, induït-inductor, està unit al reòstat en comptes de la xarxa.
        &   Un fil de la xarxa ha d'anar directament al born comú.      \\
    \hline
El motor s'engega amb poca càrrega i s'embala.
    &   Error de muntatge: el born induïtinductor està unital reòstat i no a la xarxa.
        &   Un fil de la xarxa ha d'anar directament al born comú.      \\
    \hline
El motor s'engega massa lentament.
    &   Falta d'excitació.
        &   S'ha d'engegar sempre amb el reòstat de camp al zero.       \\
    \hline
\end{tabularx}
    \caption{Cerca d'avaries I.}
\end{table}

\end{document}

enter image description here

edit: i did't interfere in page design. in case, that you consider to have wider text width, you can obtain this with use `geometry packages, for example with adding

\usepackage[margin=25mm]{geometry}

after \documentclass{...} and you will obtain the following kooks of table:

enter image description here

  • I like it, it seems to be really useful! There's just one problem that must be solved...As you can see, my table have some multirows that you just forget...what about them? Thanks in advance!! – Abelois Aug 30 '17 at 14:51
  • sorry, i don't see any multirow in your table :), only cells whit multi line text. for them you don't need multirow cell but use type of column which automatically break longer text in more lines. a case of such column type is X type from package tabularx (as used in my answer) or p{<column width>}, which can be used also in tabular environment. do you test my solution? do you obtain desired result? as you can see, the code is (far) more concise and clear as yours. – Zarko Aug 30 '17 at 16:16
  • @Abelois, see edit of my answer. i try to improve contained explanation and show possible result, if you change page layout. – Zarko Aug 30 '17 at 16:49
  • You are right about not use adjustbox to shrink tables, but the OP doesn't do this. He only uses it to center the tabular and make a table float out of it. – Martin Scharrer Mar 22 '18 at 6:45

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