4

enter image description here

So I'm getting this error when trying to do a large table.

this is the code I've used:

\documentclass[journal]{IEEEtran}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{colortbl}
\newcommand{\gray}{\rowcolor[gray]{.90}}
\newcommand{\rgb}{\rowcolor[rgb]{0,1,0}}
\usepackage{tabularx,booktabs}

\begin{document}

\begin{figure}[h!]
\begin{center}
%\resizebox{16cm}{!} {
      \begin{tabular}{|>{\columncolor[gray]{0.9}}c|c|c|c|c|c|c|c|}
    \hline
    \rowcolor[gray]{0.9}
    Problem description & Flight phase & Consequence, effect & 
Classification & Mitigator measure & Defense & Probability \\ \hline 
Actuator A1 Fail& Taxi & Wing gets stuck, high chances of canceling flight & E & Actuator divided in more sections & NA & NA \\ \hline
Actuator A1 Fail& Take-off & Wing gets stuck, take-off becomes dangerous because there may be a possible disequilibrium & C & Divide the actuator in several pieces & Very experimented pilot to control the situation & $10^{-5}$\\ \hline
   Actuator A1 Fail& Cruise & Wing gets stuck, disequilibrium plus chances of stall  & D & Divide the actuator in several parts & Find the equilibrium with the help of the engines power plus double hydraulic system in the actuators & $10^{-5}$\\ \hline
    Actuator A1 Fail & Landing & Wing gets stuck, we could easily find a missed-approach situation where we could get unaligned with the runway & C & Several actuators so lower chances of losing full control & NA & $10^{-5}$ \\ \hline
    \end{tabular}
%   }
    \caption{table 1}
\end{center}
\end{figure}

\end{document}
3
  • 4
    This is a FAQ:-) c entries are set on one line to their natural width change some of them to say p{3cm} for 3cm wide column with line wrapping (and never uncomment that resizebox, scaling tables is evil:-) May 23, 2017 at 8:56
  • Use \begin{tabular}{|>{\columncolor[gray]{0.9}}p{1.9cm}|p{1cm}|p{3.2cm}|p{1.8cm}|p{3cm}|p{2.4cm}|c|} to define the table parameters.
    – M S
    May 23, 2017 at 9:04
  • Thanks for replying but still not working, I get errors when writing that piece of code you sent. May 23, 2017 at 9:16

3 Answers 3

4

Another solution based on tabularx, makecell and eqparbox. I added some vertical padding to the rows:

\documentclass[journal]{IEEEtran}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{colortbl}
\newcommand{\gray}{\rowcolor[gray]{.90}}
\newcommand{\rgb}{\rowcolor[rgb]{0,1,0}}
\usepackage{tabularx,booktabs, makecell}
\usepackage{ragged2e, eqparbox}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.3pt}

\begin{document}

\begin{table*}
  \small
  \setlength\extrarowheight{2pt}
  \renewcommand{\tabularxcolumn}[1]{>{\RaggedRight}m{#1}}
  \renewcommand\theadfont{\small}
  \begin{tabularx}{\linewidth}{|>{\columncolor[gray]{0.9}}c|c|X|c|X|X|c|}
    \hline
    \rowcolor[gray]{0.9}
    \raisebox{0pt}[1.25\height][1.25\depth]{\eqparbox{Pd}{Problem\\ description}} &\eqparbox{Fd}{Flight\\ phase} & \thead{Consequence, effect} &
    \thead{Classif.} & \thead{Mitigator measure} & \thead{Defense} & \thead{Probab.} \\ \hline
    Actuator A1 Fail & Taxi & Wing gets stuck, high chances of canceling flight & E & Actuator divided in more sections & NA & NA \\ \hline
    Actuator A1 Fail & Take-off & Wing gets stuck, take-off becomes dangerous because there may be a possible disequilibrium & C & Divide the actuator in several pieces & Very experimented pilot to control the situation & $10⁻⁵$ \\ \hline
    Actuator A1 Fail & Cruise & Wing gets stuck, disequilibrium plus chances of stall & D & Divide the actuator in several parts & Find the equilibrium with the help of the engines power plus double hydraulic system in the actuators & $10⁻⁵$ \\ \hline
    Actuator A1 Fail & Landing & Wing gets stuck, we could easily find a missed-approach situation where we could get unaligned with the runway & C & Several actuators so lower chances of losing full control & NA & $10⁻⁵$ \\ \hline
  \end{tabularx}
  \caption{table 1}
\end{table*}

\end{document} 

enter image description here

2
  • @Mico: Not black magic (nor Hilbert's ταυ operation, Bourbaki would add): I posted an initial version of the code, before I turned figure*into table* (clipboard manager problem). Fixed. Thanks for pointing it
    – Bernard
    May 23, 2017 at 11:34
  • This is awesome, thanks all for the help! I really appreciate. Need some more time to learn... haha May 23, 2017 at 13:36
8

Some observations and comments:

  • Use a table environment, not a figure environment.

  • The IEEEtran document class uses a two-column page layout. Unfortunately, the table is simply much too wide to fit in a single column. Use a table* environment rather than a table environment to let the table material occupy the width of both columns.

  • Inside the table* environment, use a tabularx environment with width set to \textwidth.

  • Use (modified forms of the) X column type for columns 3, 5, and 6 of the 7-column tabularx environment.

  • Last but not least, since you're already loading the booktabs package, make use of its macros -- esp. \toprule, \midrule, \bottomrule, and \addlinespace -- and don't use \hline anywhere. In addition, don't use any vertical rules; they simply aren't needed. Also, consider not using shading for the header row and the left-hand column.

Incidentally, I would very much hope that the defensive measure for the second scenario involves a "very experienced pilot" rather than a "very experimented pilot"... :-)

A full MWE:

enter image description here

\documentclass[journal]{IEEEtran}
\usepackage{tabularx,booktabs,ragged2e,newtxmath}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}
\begin{document}

\begin{table*}
\begin{tabularx}{\textwidth}{@{}llYcYYc@{}}
\toprule
Problem description & Flight phase & Consequence, effect & Classification & Mitigator measure & Defense & Probability \\ 
\midrule
Actuator A1 Fail& Taxi     & Wing gets stuck, high chances of canceling flight & E & Actuator divided in more sections & NA & NA \\ \addlinespace
Actuator A1 Fail& Take-off & Wing gets stuck, take-off becomes dangerous because there may be a possible disequilibrium & C & Divide the actuator in several pieces & Very experienced pilot to control the situation & $10^{-5}$\\ \addlinespace
Actuator A1 Fail& Cruise   & Wing gets stuck, disequilibrium plus chances of stall  & D & Divide the actuator in several parts & Find the equilibrium with the help of the engines power plus double hydraulic system in the actuators & $10^{-5}$\\ \addlinespace
Actuator A1 Fail& Landing  & Wing gets stuck, we could easily find a missed-approach situation where we could get unaligned with runway & C & Several actuators, hence lower chances of losing full control & NA & $10^{-5}$ \\
\bottomrule
\end{tabularx}

\medskip
\caption{A two-column table}
\end{table*}
\end{document} 
2
  • Could you please let me know, what are the rules of the tabularx environment. I mean how to set the X column and Y column values.
    – M S
    May 23, 2017 at 12:50
  • 1
    @SibaMishra - The main rule is that there must be at least one column of type X in any tabularx environment. The width of the X column (or columns) is the residual after the widths of all non-X columns have been subtracted from the overall width (here: \textwidth). The contents of an X column are fully justified by default; the Y column that's used in my answer is just an X column whose contents are typeset ragged-right instead of fully justified. The package's user guide provides a lot more information.
    – Mico
    May 23, 2017 at 13:47
4
\documentclass[journal]{IEEEtran}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{colortbl}
\newcommand{\gray}{\rowcolor[gray]{.90}}
\newcommand{\rgb}{\rowcolor[rgb]{0,1,0}}
\usepackage{tabularx,booktabs}
\begin{document}
\begin{figure}[h!]
\begin{center}
\begin{tabular}{|>{\columncolor[gray {0.9}}p{1.9cm}|p{1cm}|p{3.2cm}|p{1.8cm}|p{3cm}|p{2.4cm}|c|}
\hline
\rowcolor[gray]{0.9}
Problem description & Flight phase & Consequence, effect & Classification & Mitigator measure & Defense & Probability \\ \hline 
Actuator A1 Fail& Taxi & Wing gets stuck, high chances of canceling flight & E & Actuator divided in more sections & NA & NA \\ \hline
Actuator A1 Fail& Take-off & Wing gets stuck, take-off becomes dangerous because there may be a possible disequilibrium & C & Divide the actuator in several pieces & Very experimented pilot to control the situation & $10^{-5}$\\ \hline
Actuator A1 Fail& Cruise & Wing gets stuck, disequilibrium plus chances of stall  & D & Divide the actuator in several parts & Find the equilibrium with the help of the engines power plus double hydraulic system in the actuators & $10^{-5}$\\ \hline
Actuator A1 Fail & Landing & Wing gets stuck, we could easily find a missed-approach situation where we could get unaligned with the runway & C & Several actuators so lower chances of losing full control & NA & $10^{-5}$ \\ \hline
\end{tabular}
\caption{table 1}
\end{center}
\end{figure}
\end{document}

Its working. Check the attached screenshot.enter image description here

2
  • 1
    +1. It would be helpful if you provided a couple of sentences to state (a) what the main ingredients of the solution consist of and (b) how the "ingredients" are implemented in LaTeX.
    – Mico
    May 23, 2017 at 10:49
  • Please also describe if (and how) you ascertained that the tabular environment fits into the width of either one or both columns of text.
    – Mico
    May 23, 2017 at 11:58

You must log in to answer this question.

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