0

I have a table with the length and width of each column already defined. I just need to use \multicolumn and still keep the lenght and width. When I tried it i obtained an error so I don't how exactly to write it.

The table must have the width of the page or a little bit smaller that is why I use \parbox.

This what my table should look like

This is what I tried:

\documentclass[11pt,fleqn]{article}

\usepackage[english]{babel}

\usepackage{mathtools}
\usepackage{geometry}
\usepackage{xcolor,fancyhdr}
\usepackage{array,multirow,colortbl}

\begin{document}

\setlength{\fboxsep}{0pt}%
\colorbox{lightgray}{%
\arrayrulecolor{white}%
\begin{tabular}{| l | l | l |}
\hline
\parbox[c][0.28in][c]{2.9in}{\smallskip\centering\textbf{Component}} & 
\parbox\multicolumn{2}{c}[0.28in]{2.9in}{\smallskip\centering\textbf{Component equations}}\\ \hline

\parbox[c][0.64in][c]{3in}{\centering{Resistance}} &
\parbox[c][0.64in][c]{3in}{\centering{ U_{R}(t) = R\cdot i_{R} (t) }} &
\parbox[c][0.64in][c]{3in}{\centering{U_{R}(t) = R\cdot i_{R}(t) }}\\ \hline 

\end{tabular}%
}

\end{document}
7
  • Welcome to TeX SX! Your code use no \multirow.
    – Bernard
    Sep 11, 2020 at 14:03
  • Sorry I meant \multicolumn. I edited my question
    – user221638
    Sep 11, 2020 at 14:09
  • Do you really need to fix the height of each \parbox?
    – Bernard
    Sep 11, 2020 at 14:12
  • Yes my table is longer than that and I need the height to be large
    – user221638
    Sep 11, 2020 at 14:14
  • \parbox\multicolumn ??? Sep 11, 2020 at 14:24

2 Answers 2

1

It was hard to see the intended layout as there were unrelated errors (eg the equations need to be in math mode) but I can not see why you need \parboxes here at all, something like this is I think the intended layout with much simpler markup.

enter image description here

Two versions, one set natural width, one with column widths specified.

\documentclass[11pt,fleqn]{article}

\usepackage[english]{babel}

\usepackage{mathtools}
\usepackage{geometry}
\usepackage{xcolor,fancyhdr}
\usepackage{array,multirow,colortbl}

\begin{document}

\begin{center}
\setlength{\fboxsep}{0pt}%
\colorbox{lightgray}{%
\arrayrulecolor{white}%
\renewcommand\arraystretch{2.5}%
\begin{tabular}{| c | c | c |}
\hline
\textbf{Component} & 
\multicolumn{2}{c}{\textbf{Component equations}}\\ \hline

Resistance &
$ U_{R}(t) = R\dot i_{R} (t)$ &
$U_{R}(t) = R\dot i_{R}(t) $\\ \hline 

\end{tabular}%
}
\end{center}

\hrule

\begin{center}
\setlength{\fboxsep}{0pt}%
\colorbox{lightgray}{%
\arrayrulecolor{white}%
\renewcommand\arraystretch{2.5}%
\begin{tabular}{| wc{3.5cm} | wc{5cm} | wc{5cm} |}
\hline
\textbf{Component} & 
\multicolumn{2}{c}{\textbf{Component equations}}\\ \hline

Resistance &
$ U_{R}(t) = R\dot i_{R} (t)$ &
$U_{R}(t) = R\dot i_{R}(t) $\\ \hline 

\end{tabular}%
}
\end{center}

\end{document}
3
  • The table must have the width of the page or a little bit smaller that is why I use \parbox I added a picture of my table done with Word
    – user221638
    Sep 12, 2020 at 9:40
  • @Hailey You can specify the column widths by replacing c in the argument to tabular (a natural width centred column) by wc{4cm} a centred column of width 4cm or whatever widths you want. Look in a minute I will extend the answer Sep 12, 2020 at 10:02
  • Thank you but it's still not like in my picture.. It is for my professor and he is verry demanding. the first row is less larger than the other rows
    – user221638
    Sep 12, 2020 at 10:13
0

With the help of tabularx in order to make sure the table is as wide as the textwidth, a custom column type in order to horizontally center the contents, \rowcolors (which is available when loading the xcolor package with the tables option to color the table background, \setlength{\arrayrulewidth}{1pt} to increase the visibility of the lines and the cellspace package in order to add some space above and below the contents of each cell:

enter image description here

\documentclass[11pt,fleqn]{article}

\usepackage[english]{babel}

\usepackage{mathtools}
\usepackage{geometry}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\usepackage[column=0]{cellspace}
\setlength{\cellspacetoplimit}{1.5\tabcolsep}
\setlength{\cellspacebottomlimit}{\cellspacetoplimit}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\addparagraphcolumntypes{X,C}
\begin{document}


\arrayrulecolor{white}
\rowcolors{1}{lightgray}{lightgray}
\setlength{\arrayrulewidth}{1pt}
\noindent
\begin{tabularx}{\textwidth}{0{C} | >{\(}0{C}<{\)} | >{\(}0{C}<{\)} }
\textbf{Component} & 
\multicolumn{2}{c}{\textbf{Component equations}}\\ \hline
Resistance &
U_{R}(t) = R\cdot i_{R} (t)  &
U_{R}(t) = R\cdot i_{R}(t) \\ 
\end{tabularx}




\end{document}

You must log in to answer this question.