0

I am facing problems with coloring cells in my table. I am using sharelatex and the documentclass report. The pictures shows my code, and how it is displayed. It just prints out the text instead of coloring the cells. Does anybody know what is wrong and how to fix the problem?

The Code:

\usepackage{color}
\usepackage{colortbl}

\begin{table}[H]
    \centering
    \begin{tabular}{c|c|c|c|c}
    & CFRP & Aluminum & Polyurethane BM5172 & Steel alloy\\
    \hline
    \hline
    Density [g/cm$^3$] & \cellcolor{yellow}1.5 & 2.7-2.8 & 1.2 & 7.75-8.05
    \cite{Steel_density}\\
    \hline
    Compressive strength [MPa] & 570 \cite{CFRP_properties} & 30-280
    \cite{Alu_comp} & 65 & 200-2100 \cite{Steel_comp}\\
    \hline
    Ease of machining & & & &
    \end{tabular}
    \caption{Material choice}
    \label{tab:Material_choice}
\end{table}  

display

  • 2
    Welcome to TeX - LaTeX! Please post your code, not a picture of the code. Also make sure that it is compilable. What you post has no \documntclass nor any \begin{document}. – Andrew Swann Apr 22 '18 at 14:58
  • 1
    You should place your \usepackage{} calls before specifying \begin{document}. – epR8GaYuh Apr 22 '18 at 15:00
  • Documentclass and beginning of document is written at the beginning of the document. Like this:"\documentclass[../main.tex]{subfiles} \begin{document} " The subfiles are imported into the main file, which works fine. – Atle Apr 22 '18 at 15:18
  • Using \usepackage{} before \begin{document} did not make any difference to the results. – Atle Apr 22 '18 at 15:19
  • When using the subfiles package, you probably have to include the needed packages in the preamble of your main file. – epR8GaYuh Apr 22 '18 at 15:24
1

For me it compiles normally, after I've completed your code. However I think you don't have to reinvent the wheel and define a command for the common formatting of column heads: the makecell package already offers a \thead command, and it lets you break lines in standard cells:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{colortbl}
\usepackage{tabularx, float, makecell}
\renewcommand{\theadfont}{\normalsize\itshape\bfseries}

\usepackage[table, svgnames, x11names]{xcolor}

\begin{document}
\begin{table}[H]
\centering\setlength{\extrarowheight}{2pt}
\begin{tabular}{c|c|c|c|c}
 & \thead{CFRP} & \thead{Aluminum} & \thead{Polyurethane\\ BM5172} & \thead{Steel alloy}\\
\hline
\hline
Density [g/cm$^3$] & \cellcolor{yellow}1.5 & 2.7-2.8 & 1.2 & 7.75-8.05
\cite{Steel_density}\\
\hline
Compressive strength [MPa] & 570 \cite{CFRP_properties} & 30-280
\cite{Alu_comp} & 65 & 200-2100 \cite{Steel_comp}\\
\hline
Ease of machining & & & &
\end{tabular}
\caption{Material choice}
\label{tab:Material_choice}
\end{table}

\end{document} 

enter image description here

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.