3

I created the following latex table in booktabs style and colored each cell with a different colour. But in the end, I saw some padding which is not coloured because of the different size of the cell's content. How can I solve this problem?

my coloured table

But I just wanted to create following table:

the actual table

Here is the code of the latex table. It is a little bit long but it can be useful to understand the problem.

\usepackage{colortbl}
\usepackage{booktabs}
\definecolor{gray1}{RGB}{238,236,225}
\definecolor{gray2}{RGB}{224,224,224}
\definecolor{oran1}{RGB}{255,192,0}
\definecolor{yelw1}{RGB}{255,227,111}
\definecolor{blue1}{RGB}{197,217,241}
\definecolor{gree1}{RGB}{196,215,155}
\definecolor{crea1}{RGB}{252,245,238}
\definecolor{pink1}{RGB}{218,150,148}

\begin{table}[]
\centering
\caption{Raylı Sistemlerde Maliyet Optimizasyonu}
\label{tab:optOneri}
\resizebox{\columnwidth}{!}{%
\begin{tabular}{@{}cccccccccc@{}}
\rowcolor{gray1}
\multicolumn{10}{c}{Maliyet Optimizasyonu}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    \\
                                                                & \multicolumn{4}{c}{\cellcolor{gray2}İlk Yapım Maliyeti}                                                                                                                                                                                                                                     & \multicolumn{5}{c}{\cellcolor{pink1}İşletme Maliyeti}                                                                                                                                                                                                                                                                                                                                                                                                            \\
\begin{tabular}[c]{@{\cellcolor{yelw1}}c@{}}Dizideki Araç \\ Sayısı\end{tabular} & \begin{tabular}[c]{@{\cellcolor{blue1}}c@{}}Toplam İstasyon\\ Maliyeti\end{tabular} & \begin{tabular}[c]{@{\cellcolor{blue1}}c@{}}Toplam Hatyapım\\ Maliyeti\end{tabular} & \begin{tabular}[c]{@{\cellcolor{blue1}}c@{}}Toplam Araç\\ Maliyeti\end{tabular} & \begin{tabular}[c]{@{\cellcolor{oran1}}c@{}}Toplam Yapım\\ Maliyeti\end{tabular} & \begin{tabular}[c]{@{\cellcolor{yelw1}}c@{}}Toplam\\ İstasyon\\ İşletme\\ Maliyeti\\ (yıllık)\end{tabular} & \begin{tabular}[c]{@{\cellcolor{yelw1}}c@{}}Toplam\\ Hat\\ İşletme\\ Maliyeti\\ (yıllık)\end{tabular} & \begin{tabular}[c]{@{\cellcolor{yelw1}}c@{}}Toplam\\ Sistem\\ İşletme\\ Maliyeti\\ (yıllık)\end{tabular} & \begin{tabular}[c]{@{\cellcolor{pink1}}c@{}}Toplam\\ İşletme\\ Maliyeti\\ (yıllık)\end{tabular} & \begin{tabular}[c]{@{\cellcolor{pink1}}c@{}}Toplam\\ İşletme\\ Maliyeti\\ (20 yıllık)\end{tabular} \\
\rowcolor{crea1}4                                              &                                                                    &                                                                    &                                                                &                                                                 &                                                                                           &                                                                                      &                                                                                         &                                                                                &                                                                                   \\
\rowcolor{crea1}5                                              &                                                                    &                                                                    &                                                                &                                                                 &                                                                                           &                                                                                      &                                                                                         &                                                                                &                                                                                   \\
\rowcolor{crea1}6                                              &                                                                    &                                                                    &                                                                &                                                                 &                                                                                           &                                                                                      &                                                                                         &                                                                                &                                                                                   \\
\rowcolor{crea1}8                                              &                                                                    &                                                                    &                                                                &                                                                 &                                                                                           &                                                                                      &                                                                                         &                                                                                &                                                                                  

\end{tabular}
}
\end{table}

Thank you.

2

Here is a simple solution with the \makecell commands that replaces the nested tabular environments. The makecell package allows for line breaks inside cells. Additionally, I don't use \resizebox, and replace it simply with a smaller fontsize and \tabcolsep, and load caption for a correct vertical spacing between caption and table.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
\usepackage{colortbl}
\usepackage{array, makecell, caption}
\definecolor{gray1}{RGB}{238,236,225}
\definecolor{gray2}{RGB}{224,224,224}
\definecolor{oran1}{RGB}{255,192,0}
\definecolor{yelw1}{RGB}{255,227,111}
\definecolor{blue1}{RGB}{197,217,241}
\definecolor{gree1}{RGB}{196,215,155}
\definecolor{crea1}{RGB}{252,245,238}
\definecolor{pink1}{RGB}{218,150,148}

\begin{document}
\begin{table}[]
  \centering\footnotesize
  \setlength\tabcolsep{5pt}
  \caption{Raylı Sistemlerde Maliyet Optimizasyonu}
  \label{tab:optOneri}
    \begin{tabular}{@{}*{10}{c}@{}}
      \rowcolor{gray1}
      \multicolumn{10}{@{}c@{}}{Maliyet Optimizasyonu} \\
      & \multicolumn{4}{c}{\cellcolor{gray2}İlk Yapım Maliyeti} & \multicolumn{5}{c@{}}{\cellcolor{pink1}İşletme Maliyeti} \\
      \cellcolor{yelw1}\makecell{Dizideki \\Araç \\ Sayısı} &
      \cellcolor{blue1}\makecell{Toplam\\ İstasyon\\ Maliyeti} & \cellcolor{blue1}\makecell{Toplam\\ Hatyapım\\ Maliyeti} & \cellcolor{blue1}\makecell{Toplam\\ Araç\\ Maliyeti} & \cellcolor{oran1}\makecell{Toplam\\ Yapım\\ Maliyeti} & \cellcolor{yelw1}\makecell{Toplam\\ İstasyon\\ İşletme\\ Maliyeti\\ (yıllık)} & \cellcolor{yelw1}\makecell{Toplam\\ Hat\\ İşletme\\ Maliyeti\\ (yıllık)} & \cellcolor{yelw1}\makecell{Toplam\\ Sistem\\ İşletme\\ Maliyeti\\ (yıllık)} & \cellcolor{pink1}\makecell{Toplam\\ İşletme\\ Maliyeti\\ (yıllık)} & \cellcolor{pink1}\makecell{Toplam\\ İşletme\\ Maliyeti\\ (20 yıllık)} \\
      \rowcolor{crea1}4 & & & & & & & & & \\
      \rowcolor{crea1}5 & & & & & & & & & \\
      \rowcolor{crea1}6 & & & & & & & & & \\
      \rowcolor{crea1}8 & & & & & & & & &
    \end{tabular}
\end{table}

\end{document} 

enter image description here

  • Very nice answer, very nice solution, you gave me more than I asked. Thank you very much. – beerobot Dec 9 '15 at 11:42

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.