1

Hello here is my effort for creating a table similar to what we do in MS Word. I am trying to learn how to create a nice table with this example. However, I do not know where the error source is.

\documentclass[12pt,twoside]{mitthesis}

\begin{tabular}{ |p{3cm}||p{6cm}|p{3cm}| }
     \hline
     \multicolumn{5}{|c|}{Parameter for fatigue crack growth prediction} \\
     \hline
     Case \#     & Elastic-Plastic Constants &$\rho^*$\\

 Sink-hole   & 4.64\times 10^-11    &10 &0.0909&3.4\times 10^-6\\
 Miss-hole&   7.84\times 10^-11  & 10  &0.0909 &\times 2.6\times 10^-6 \\

 \hline
\end{tabular}
\end{document}

Here is the table that I need to generate:

enter image description here

6
  • Can you make that a complete, but minimal example that others can compile? (In LaTeX, that means starting with \documentclass and ending with \end{document} and not including stray code or packages that are unrelated to the question/problem.)
    – jon
    Apr 2, 2017 at 4:57
  • @jon You are right. I added these. However, the written code is related to the question that I've asked.
    – Mohammad
    Apr 2, 2017 at 5:00
  • @jon is that fair enough ?
    – Mohammad
    Apr 2, 2017 at 5:02
  • It is missing the \begin{document} and \end{document} lines, and I don't see what graphicx (and related) as to do with the issue; and I have no idea what lgrind is.
    – jon
    Apr 2, 2017 at 5:10
  • 1
    @jon this is a simple table...let user use their own class of document. It is obvious that we need \begin and so on. The goal is to fix the table, learning advanced table. Every beginner knows how to compile the code. My goal here is just to show a partial effort for creating a table. But thanks for comment.
    – Mohammad
    Apr 2, 2017 at 5:15

2 Answers 2

6

enter image description here

Colors of rows and rules follows to example of table shown in question. Table format is according to forms suggested with booktabs, but it is not used in table. For numbers formatting is used S column type from package siunitx. Also is corrected number of columns and added definitions for colors and missed package for coloring of table.

\documentclass[12pt,twoside]{book}
\usepackage[table]{xcolor}
\usepackage{siunitx}

\begin{document}
    \begin{table}
\setlength\tabcolsep{9pt}    
\rowcolors{1}{white}{cyan!25}
\arrayrulecolor{cyan}
\setlength\arrayrulewidth{1pt}
    \centering
\begin{tabular}{ l S[table-format=1.2,
                          table-figures-exponent=2]
                        S[table-format=2.0]
                        S[table-format=1.4]
                        S[table-format=1.1,
                          table-figures-exponent=2]  
                }           
     \hline
Case \#     & \multicolumn{3}{c}{Elastic-Plastic Constants} &   $\rho^*$    \\
     \hline
            &   $C$         &   $\gamma$    &   $p$         &               \\
Sink-hole   &   4.64e-11    &   10          &   0.0909      &   3.4e-6      \\
Miss-hole   &   7.84e-11    &   10          &   0.0909      &   2.6e-6      \\
 \hline
\end{tabular}
    \caption{Parameter for fatigue crack growth prediction}
\label{tab:mytab}
    \end{table}
\end{document}

For nice table design is worth to look in "Less is more". According to this suggestions your table should be:

enter image description here

\documentclass[12pt,twoside]{book}
\usepackage{siunitx}
\usepackage{booktabs}

\begin{document}
    \begin{table}
\setlength\tabcolsep{9pt}    
    \centering
\begin{tabular}{ l S[table-format=1.2,
                          table-figures-exponent=2]
                        S[table-format=2.0]
                        S[table-format=1.4]
                        S[table-format=1.1,
                          table-figures-exponent=2]  
                }           
     \toprule
Case \#     & \multicolumn{3}{c}{Elastic-Plastic Constants} &   $\rho^*$    \\
     \cmidrule(lr){2-4}
            &   $C$         &   $\gamma$    &   $p$         &               \\
     \midrule
Sink-hole   &   4.64e-11    &   10          &   0.0909      &   3.4e-6      \\
Miss-hole   &   7.84e-11    &   10          &   0.0909      &   2.6e-6      \\
    \bottomrule
\end{tabular}
    \caption{Parameter for fatigue crack growth prediction}
\label{tab:mytab}
    \end{table}
\end{document}
1
  • Thanks much. So, informative answer. I have given vote up!
    – Mohammad
    Apr 2, 2017 at 13:47
1

The following code should work.

table

I've done the following:

  • added columns (you need as many columns as you want to use &, what's btw easy to check)
  • added your row colors (package xcolor)
  • moved what looked like a caption into a real caption (you can position it by moving \caption around)
  • inserted the missing math start/end points
  • inserted \begin{document} and \end{document} (they are essential for LaTeX documents and MWEs too)

\documentclass{article}
\usepackage{amsmath,amsfonts,amssymb,array}
\usepackage[table]{xcolor}

\begin{document}
\begin{table}[h]
\rowcolors{2}{white}{gray!25}
\begin{tabular}{ |p{3cm}||>{\centering}p{2cm}>{\centering}p{2cm}>{\centering}p{2cm}|p{3cm}| }
     \hline
     Case \#     & \multicolumn{3}{c|}{Elastic-Plastic Constants} &$\rho^*$\\\hline
    & $C$ & $\gamma$ & $p$ &\\
 Sink-hole   & $4.64\times 10^-11$ & 10 &0.0909& $3.4\times 10^-6$\\
 Miss-hole&   $7.84\times 10^-11$  & 10  &0.0909 & $2.6\times 10^-6 $\\

 \hline
\end{tabular}
\caption{Parameter for fatigue crack growth prediction}
\end{table}
\end{document}
3
  • 2
    you might be interested in the booktabs package. On page 3 it's documentation states that "You will not go far wrong if you remember two simple guidelines at all times: 1. Never, ever use vertical rules. 2. Never use double rules."
    – jakun
    Apr 2, 2017 at 6:00
  • @jakun You don't have to blame me for that. It's just the OP's dirty code in a fixed version.
    – TeXnician
    Apr 2, 2017 at 6:03
  • I am sorry, I did not want to offend you. True, I did not look at the code in the question, I have just seen that the table layout asked for does not have vertical rules and that your answer does.
    – jakun
    Apr 2, 2017 at 6:08

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.