1

Consider the following table. Some of the text in the second column is italic and also the text is broken in order to fit the column width.

This is the table that I am working on.

When the following code is used, it generates a table where the text can be formatted however the table grows outside the page boundary.

\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabularx}{0.7\textwidth}{llll}
\hline
\multirow{2}{*}{\textbf{S\#}} & \multicolumn{2}{c}{\textbf{Required Input}}   & \multirow{2}{*}{\textbf{Output}} \\ \cline{2-3}
                     & \textbf{1-level}   & \textbf{2-level} &   \\     \hline

E-call (EC) & Vehicle information, e.g., type and id, vehicle location,\ \textit{freight information, e.g., type and amount.} & Any output here. \ \hline \end{tabularx} \end{table}

See picture 2, which is the screenshot of the code:

enter image description here

2

Environment tabularx is already be used, only the usage of the column type X is missing. Also it seems the entries should be vertically centered, this can be achieved by the redefinition of \tabularxcolumn to internally use column type m instead of p. Also the example uses the lines of package booktabs.

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{multirow}
\usepackage{tabularx}

\begin{document}
\begin{table}
  \centering
  \caption{My caption}
  \label{my-label}
  \renewcommand*{\tabularxcolumn}[1]{m{#1}}
  \begin{tabularx}{\linewidth}{
    c
    >{\raggedright}X
    >{\raggedright}X
    >{\raggedright\arraybackslash}X
  }
    \toprule
    \multirow{2}{*}{\raisebox{-1ex}{\textbf{S\#}}}
    &\multicolumn{2}{c}{\textbf{Required Input}}
    & \multirow{2}{\linewidth}{%
      \centering\raisebox{-1ex}{\textbf{Output}}} \\
    \cmidrule{2-3}
    & \textbf{1-level}   & \textbf{2-level} &   \\
    \midrule
    1
    & Vehicle information, e.g., type and id, vehicle location,
      \textit{freight information, e.g., type and amount.}
    &
    & Any output here \\
    \bottomrule
  \end{tabularx}
\end{table}
\end{document}

Result

3

If I understand your question correctly, than you wish something like this: enter image description here

From your (not complete code) I made the following MWE:

\documentclass{article}

    \usepackage{makecell,multirow,tabularx}
    \newcolumntype{R}{>{\raggedright\arraybackslash}X}
    \renewcommand\theadfont{\bfseries}

    \begin{document}
\begin{table}[h]
    \centering
    \small
\caption{My caption}
\label{my-label}
    \begin{tabularx}{\textwidth}{cRRR}
\hline
\multirowcell{2}{\thead{S\#}} 
    &   \multicolumn{2}{c}{\thead{Required Input}}   
        &   \multirowcell{2}{\thead{Output}}    \\ 
    \cline{2-3}
    & \thead{1-level}   & \thead{2-level} &     \\     
    \hline
1   & \itshape
        \textbf{vehicle information},
        eg. type and id,\newline 
        \textbf{freight information},
        eg., type and output
        &               & Any output here       \\
    \hline
    \end{tabularx}
\end{table}
    \end{document}

In preamble I add two packages: makecell and multirow, redefine \thead macro so, that the column heads are in boldface. For some words in table I uase textbf{...}.

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.