4

How to make head of table like in the picture? Thank you enter image description here

\documentclass{article}
\usepackage{array}
\usepackage{makecell, multirow, booktabs}
\usepackage{caption}

\begin{document}

\begin{table}[h]
    \centering
    \caption{title}
    \footnotesize\setlength{\extrarowheight}{2pt}
    \begin{tabular}{ccccccccccc}
        \toprule
        \multirowcell{1}[-1pt]{Element} & \multirowcell{3}[-1pt]{\citep{M}} & \multirowcell{2}[-1pt]{\citep{C}} & \multirowcell{1}[-1pt]{\citep{R}}& \multirowcell{3}[-1pt]{\citep{P}} \\
        \cmidrule(lr){5-6}
        & \multicolumn{3}{c}{PHOEBE fotometrie a RV} & \multicolumn{1}{c}{\multirow{2}{*}{POWR analýza} & \multicolumn{1}{c}{\multirow{2}{*}{Řešení světelných křivek a RV} & \multicolumn{1}{c}{\multirow{2}{*}{CFF} } & \multicolumn{3}{c}{Model} \\

& \multicolumn{1}{c}{Řešení I} & \multicolumn{1}{c}{Řešení II} & \multicolumn{1}{c}{Řešení III} &  &  & & \multicolumn{1}{c}{malá hmotnost} & \multicolumn{1}{c}{střední hmotnost} & \multicolumn{1}{c}{velká hmotnost} \\        

        \midrule
& & & & & & & & & &
        \bottomrule
    \end{tabular}
    \label{table}
\end{table}

\end{document} 

EDIT

\documentclass[12pt,a4paper]{report}
\setlength\textwidth{145mm}
\setlength\textheight{247mm}
\setlength\oddsidemargin{15mm}
\setlength\evensidemargin{15mm}
\setlength\topmargin{0mm}
\setlength\headsep{0mm}
\setlength\headheight{0mm}
\let\openright=\clearpage

\usepackage{amsmath, graphicx}
\usepackage{array}

\usepackage{caption}
\usepackage[output-decimal-marker={,}]{siunitx}
\NewDocumentCommand{\anote}{}{\makebox[0pt][l]{$^*$}}

\usepackage[usenames]{xcolor}
\usepackage[a-2u]{pdfx}
\usepackage[english,czech]{babel}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[utf8]{inputenc}

\usepackage{amsfonts}       % matematické fonty
\usepackage{amsthm}         % sazba vět, definic apod.
\usepackage{bbding}         % balíček s nejrůznějšími symboly
                % (čtverečky, hvězdičky, tužtičky, nůžtičky, ...)
\usepackage{bm}             % tučné symboly (příkaz \bm)
\usepackage{fancyvrb}       % vylepšené prostředí pro strojové písmo
\usepackage{indentfirst}    % zavede odsazení 1. odstavce kapitoly
\usepackage{natbib}         % zajištuje možnost odkazovat na literaturu
                % stylem AUTOR (ROK), resp. AUTOR [ČÍSLO]
\usepackage[nottoc]{tocbibind} % zajistí přidání seznamu literatury,
                            % obrázků a tabulek do obsahu
\usepackage{icomma}         
\usepackage{booktabs}       % lepší vodorovné linky v tabulkách
\usepackage{paralist}       % lepší enumerate a itemize
\usepackage{makecell}
\usepackage{amssymb}
\usepackage{dcolumn}
\setlength\heavyrulewidth{0.25ex}
\usepackage{cellspace, multirow, tabularx}
\newcommand{\mc}[1]{\multicolumn{1}{c}{#1}}
\usepackage{ragged2e}
\newcolumntype{d}[1]{D{.}{,}{#1}}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\newcommand\stack[1]{\multicolumn{1}{c}{\shortstack{#1}}}
\newcommand{\angstrom}{\mbox{\normalfont\AA}}

\newcolumntype{C}{>{\Centering\arraybackslash\hspace{0pt}}X}
\newcommand\mytab[1]{%
   \bgroup%
   \setlength\extrarowheight{0pt}%
   \smash{\begin{tabular}[t]{@{}c@{}} #1 \end{tabular}}%
   \egroup}
%%% code block to handle the OP's follow-up question -- see
%%% https://tex.stackexchange.com/a/112002/5001 for the source
\usepackage{regexpatch}
\makeatletter
% Change the `-` delimiter to an active character
\xpatchparametertext\@cline{-}{\cA-}{}{}
\makeatother

\begin{document}


\begin{table}[ht!]
\setlength\extrarowheight{2pt}
\setlength\tabcolsep{3pt}  % default: 6pt
\begin{tabularx}{\textwidth}{| *{4}{C|} >{\hsize=1.3\hsize}C| >{\hsize=0.7\hsize}C| *{3}{C|}}
\hline
\multicolumn{3}{|c|}{M} & \multicolumn{2}{c|}{C} & R & \multicolumn{3}{ c|}{P} \\
\hline
\multicolumn{3}{|c|}{PHOEBE fotometrie a RV} & 
\mytab{POWR\\analýza} & 
\mytab{Řešení\\světelných\\křivek a RV} & 
CFF & \multicolumn{3}{c|}{Model} \\
\cline{1-3} \cline{7-9}
Řešení I & Řešení II & Řešení III & & & & malá hmotnost & střední hmotnost & velká hmotnost\\
\hline\hline
& & & & & & & & \\
\hline
& & & & & & & & \\
\hline
\end{tabularx}
\end{table}

\end{document}
Elisabeth
  • 1,009
  • Is it important that the underlying 9 columns have the same widths? Should line-wrapping be allowed inside the cells? – Mico Dec 08 '18 at 06:04
  • No, columns don't have same widths - it depends on situation. Yes line-wrapping be allowed inside the cells. – Elisabeth Dec 08 '18 at 06:21
  • You should really, really try much harder not to load packages more than once. What exactly are you trying to achieve by loading amsmath, graphicx, array, babel, multirow, xcolor, lmodern [3 times!], textcomp, bm, dcolumn, tocbibind, tabularx [3 times!], and ragged2e twice or even three times? Absolutely nothing good -- and quite possibly something bad -- is going to result from this bad habit. After you've cleaned out the duplicates, you should probably also examine whether all packages that remain are even needed. – Mico Dec 08 '18 at 09:58

2 Answers2

8

Like this?

enter image description here

\documentclass{article}
\usepackage[a4paper,margin=2.5cm]{geometry} % set suitable page parameters
\usepackage[T1]{fontenc}
\usepackage{lmodern,tabularx,ragged2e}
\newcolumntype{C}{>{\Centering\arraybackslash\hspace{0pt}}X}
\newcommand\mytab[1]{%
   \bgroup%
   \setlength\extrarowheight{0pt}%
   \smash{\begin{tabular}[t]{@{}c@{}} #1 \end{tabular}}%
   \egroup}
%%% code block to handle the OP's follow-up question -- see
%%% https://tex.stackexchange.com/a/112002/5001 for the source
\usepackage[czech]{babel}
\usepackage{regexpatch}
\makeatletter
% Change the `-` delimiter to an active character
\xpatchparametertext\@cline{-}{\cA-}{}{}
\makeatother
%%% end of additional code

\begin{document}

\begin{table}[ht!]
\setlength\extrarowheight{2pt}
\setlength\tabcolsep{3pt}  % default: 6pt
\begin{tabularx}{\textwidth}{| *{4}{C|} 
    >{\hsize=1.3\hsize\linewidth=\hsize}C|    
    >{\hsize=0.7\hsize\linewidth=\hsize}C| 
    *{3}{C|}}
\hline
\multicolumn{3}{|c|}{M} & \multicolumn{2}{c|}{C} & R & \multicolumn{3}{ c|}{P} \\
\hline
\multicolumn{3}{|c|}{PHOEBE fotometrie a RV} & 
\mytab{POWR\\analýza} & 
\mytab{Řešení\\světelných\\křivek a RV} & 
CFF & \multicolumn{3}{c|}{Model} \\
\cline{1-3} \cline{7-9}
Řešení I & Řešení II & Řešení III & & & & malá hmotnost & střední hmotnost & velká hmotnost\\
\hline\hline
& & & & & & & & \\
\hline
& & & & & & & & \\
\hline
\end{tabularx}
\end{table}
\end{document}
Mico
  • 506,678
  • Thank you very much. And this please: [1]: https://i.stack.imgur.com/xnVjm.png ? It depens on position of \usepackage in some way? – Elisabeth Dec 08 '18 at 06:50
  • 1
    @Elisabeth - Not knowing what you wrote in terms of LaTeX code, I have no idea how to interpret the error messages you're getting. For sure, it look like your code may differ significantly from what I wrote above. – Mico Dec 08 '18 at 07:19
  • I added the whole code in my question. – Elisabeth Dec 08 '18 at 07:59
  • 1
    @Elisabeth - The problem arises from your use of the babel package with the option czech. Please see egreg's answer to the query Slovak (and Czech) babel gives problems with cmidrule and cline. In particular, do follow his instructions under the "A less invasive hack..." subheader, i.e., the code block that starts with \usepackage{regexpatch} and ends with \makeatother. I've also posted an update to my answer, to show how to make this patch work for the code shown here. – Mico Dec 08 '18 at 08:10
  • 1
    @Elisabeth - Given your font size and page size settings, you should also change \setlength\tabcolsep{3pt} to \setlength\tabcolsep{2pt}, and change \mytab{Řešení\\světelných\\křivek a RV} to \mytab{Řešení\\světel-\\ných kři-\\vek a RV}. – Mico Dec 08 '18 at 08:30
  • Thank you. I tried to follow your advice but when I tri to compile what is now in EDIT in my question, there is mistakes all the time. What I did wrong please? – Elisabeth Dec 08 '18 at 09:13
  • 1
    @Elisabeth - The new problem appears to be related to your use of the cellspace package, which is something that's not related to my answer. If you have a new question about how to make the cellspace package compatible with the rest of your code, you should post a new query. – Mico Dec 08 '18 at 09:47
  • I editted it in my question – Elisabeth Dec 08 '18 at 10:55
  • 1
    @Elisabeth - Your use of the cellspace package was not disclosed in the version of the query upon which I constructed my answer. For what it's worth, I'm not familiar with the cellspace package. In particular, I have no idea how it interacts with one or more of the many other packages you (still) load. That's why I suggested you post a new query, in which you focus solely on the cellspace (in)compatibility matter. – Mico Dec 08 '18 at 11:06
  • It works without cellspace. Thank you very much – Elisabeth Dec 08 '18 at 11:12
  • @Elisabeth - Why were you loading the cellspace package in the first place? Packages that aren't used shouldn't be loaded... – Mico Dec 08 '18 at 11:18
  • I had need it somewhere but then I deleted it and forgot to remove the package. – Elisabeth Dec 08 '18 at 11:36
4

You can try something like this:

\documentclass{article}
\usepackage{array}
\usepackage{makecell, multirow, booktabs}
\usepackage{caption}
\begin{document}

\begin{table}[h]
\centering
\caption{title}
\footnotesize\setlength{\extrarowheight}{2pt}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|}
    \hline
    \multicolumn{3}{|c|}{M} & \multicolumn{2}{c|}{C} & R & \multicolumn{3}{c|}{P} \\
    \hline
    \multicolumn{3}{|c|}{} & \multirow{2}{*}{~}& &  & \multicolumn{3}{c|}{}\\
    \cline{1-3} \cline{7-9}
    & & & & & & & & \\
    \hline
    col1 & col2 & col3 & col4 & col5 & col6 & col7 & col8  &col9 \\
    \hline
\end{tabular}
\label{table}
\end{table}
\end{document}

enter image description here

nidhin
  • 7,932
  • Thank you very much. And please, what does this error mean [1]: https://i.stack.imgur.com/8JDlp.png? It appears when I add it to main file. – Elisabeth Dec 08 '18 at 06:41
  • @Elisabeth Its difficult say without seeing the complete code. Please see this question: https://tex.stackexchange.com/q/166655/28557 – nidhin Dec 08 '18 at 06:52