3

I'm trying to make this table: enter image description here

but I can't do it. On the last line, cell division is not good: enter image description here

Can you please help me

\documentclass[czech,12pt,oneside,openright,titlepage]{book}

\usepackage[hidelinks]{hyperref} %odkazy

\usepackage{lmodern}
\usepackage[czech]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} %cestina

%\usepackage{indentfirst} % odsazení prvního odstavce
\usepackage{parskip} % nastavení odsazení odstavců

\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor} %tabulky

\usepackage{tabularx} %tabulky na celou stránku 
\newcolumntype{C}{>{\centering}X} % Centrování sloupce

\usepackage{graphicx}
\usepackage{epstopdf} % Grafgika eps
\usepackage{float}

\usepackage{pdfpages} % PDF vkládaní

\usepackage{amsmath,amsfonts,amssymb} %matematika

%\input{mathdef.sty}

\usepackage{caption}
\usepackage{subcaption}

\usepackage[font=small,labelfont=bf,format=hang]{caption}

\usepackage[a4paper, top=2.5cm, left=2cm, right=2cm, bottom=2.5cm]{geometry} % Nastavení okrajů

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\lhead {Příručka pro pracovníky dispečerského řízení}
\rhead { \qquad 2019}
\cfoot {\thepage}
\renewcommand{\headrulewidth}{0.4pt}  %zahlavi 

%\linespread{1.5}
\setlength{\parindent}{0em}% odsazení odstavce
\setlength{\parskip}{0.5em}% mezera mezi odstavci 

\usepackage{titlesec}
\titlespacing{\chapter}{0pt}{-15pt}{10pt}
\titleformat{\chapter}[hang]{\normalfont\LARGE\bfseries}{\thechapter . \ \thispagestyle{fancy}}{0pt}{} %nastavení kapitol

\newcommand{\nadpis}[1]{\large\textbf{#1} \normalsize \medskip \\ }

\renewcommand{\figurename}{Obr.}
\renewcommand{\tablename}{Tab.} %prejmenovani


\begin{document}

\begin{table}[H]
\catcode`\-=12
\centering
\begin{tabularx}{\textwidth}{|c|c|C|C|C|C|C|c|}
\hline
Nízké napětí          & jmenovité        & \multicolumn{4}{c|}{0,4 / 0,23}                     & 0,50 & 0,69 \\ \cline{2-8} 
(nn) (kV)             & max. provozovací & \multicolumn{4}{c|}{0,42 / 0,241}                   & ---  & 0,73 \\ \hline
Vysoké napětí         & jmenovité        & 3           & 6          & \multicolumn{2}{c|}{10}  & 22   & 35   \\ \cline{2-8} 
(vn) (kV)             & max. provozovací & 3,6         & 7,2        & \multicolumn{2}{c|}{12}  & 25   & 37   \\ \hline
Velmi vysoké napětí   & jmenovité        & \multicolumn{2}{c|}{110} & \multicolumn{2}{c|}{220} & ---  & ---  \\ \cline{2-8} 
(vvn) (kV)            & max. provozovací & \multicolumn{2}{c|}{123} & \multicolumn{2}{c|}{245} & ---  & ---  \\ \hline
Zvláště vysoké napětí & jmenovité        & \multicolumn{3}{c|}{400}               & \multicolumn{3}{c|}{750} \\ \cline{2-8} 
(zvn) (kV)            & max. provozovací & \multicolumn{3}{c|}{420}               & \multicolumn{3}{c|}{800} \\ \hline
\end{tabularx}
\end{table}

\end{document}
1

Here is a suggestion:

\documentclass[czech,12pt,oneside,openright,titlepage]{book}
\usepackage{lmodern}
\usepackage[czech]{babel}
\usepackage[T1]{fontenc}
\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage[a4paper, top=2.5cm, left=2cm, right=2cm, bottom=2.5cm]{geometry} % Nastavení okrajů

\begin{document}
\begin{table}
\catcode`\-=12
\centering
\begin{tabular}{|c|c|c|*{5}{wc{1cm}|}}
\hline
Nízké napětí          & jmenovité        & \multicolumn{3}{c|}{0,4 / 0,23} & 0,50 & 0,69   \\ \cline{2-7} 
(nn) (kV)             & max. provozovací & \multicolumn{3}{c|}{0,42 / 0,241} & ---  & 0,73 \\ \hline
Vysoké napětí         & jmenovité        & 3           & 6          & 10  & 22   & 35      \\ \cline{2-7} 
(vn) (kV)             & max. provozovací & 3,6         & 7,2        & 12  & 25   & 37      \\ \hline
Velmi vysoké napětí   & jmenovité        & \multicolumn{2}{c|}{110} & 220 & ---  & ---     \\ \cline{2-7} 
(vvn) (kV)            & max. provozovací & \multicolumn{2}{c|}{123} & 245 & ---  & ---     \\ \hline
Zvláště vysoké napětí & jmenovité        &\multicolumn{5}{c|}{400\hspace{1.5cm}\vline\hspace{1.5cm}750} \\ \cline{2-7}
(zvn) (kV)            & max. provozovací &\multicolumn{5}{c|}{420\hspace{1.5cm}\vline\hspace{1.5cm}800} \\ \hline
\end{tabular}
\end{table}
\end{document}

Ouput of the above code

4
  • What is the rational behind this way \multicolumn{5}{c|}{400\hspace{1.5cm}\vline\hspace{1.5cm}750} and the reduction of the columns by 1?
    – albert
    Sep 9 '20 at 14:40
  • @albert: I think that, in the tabular of the OP, there was one column with no signification. In my \multicolumn, I have adjusted the position of both elements by hand because it seems not possible with \hfill. Sep 9 '20 at 14:58
  • I think that OP wanted to split the column wanted to split the column with 10 / 12 / 220 / 245 and therefore chose to have that column to have multicolumn{2}. The current solution works for the current table, but what would happen when one of the fields gets larger numbers or the strings become larger?
    – albert
    Sep 9 '20 at 16:06
  • I have posted a second answer to the question of the OP. I think that it gives a (maybe partial) answer to your questions. Sep 9 '20 at 17:38
3

In the following program, I have used {NiceTabular} of nicematrix. This environment (similar to {tabular}) creates PGF/Tikz nodes under the cells, rows and columns of the array.

It's possible to use these nodes to draw whatever rule we want.

I have drawn the problematic rule with Tikz (exactly in the middle of the column containing 10, 12, 220 and 245) and I have put the four last numbers exactly in the middle of the cells created by the previous rule.

The positioning needs no manual adjustment (as example, I have changed 750 in 750000).

You need several compilations.

\documentclass[czech,12pt,oneside,openright,titlepage]{book}
\usepackage{lmodern}
\usepackage[czech]{babel}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amssymb}

\usepackage{nicematrix}
\usepackage{tikz}
\usepackage[a4paper, top=2.5cm, left=2cm, right=2cm, bottom=2.5cm]{geometry}


\usetikzlibrary{calc}

\begin{document}
\begin{table}
\catcode`\-=12
\centering
\begin{NiceTabular}{|c|c|c|c|c|c|c|}
\hline
Nízké napětí          & jmenovité        & \multicolumn{3}{c}{0,4 / 0,23} & 0,50 & 0,69   \\ \cline{2-7} 
(nn) (kV)             & max. provozovací & \multicolumn{3}{c}{0,42 / 0,241} & ---  & 0,73 \\ \hline
Vysoké napětí         & jmenovité        & 3           & 6          & 10  & 22   & 35      \\ \cline{2-7} 
(vn) (kV)             & max. provozovací & 3,6         & 7,2        & 12  & 25   & 37      \\ \hline
Velmi vysoké napětí   & jmenovité        & \multicolumn{2}{c}{110} & 220 & ---  & ---     \\ \cline{2-7} 
(vvn) (kV)            & max. provozovací & \multicolumn{2}{c}{123} & 245 & ---  & ---     \\ \hline
Zvláště vysoké napětí & jmenovité        & \multicolumn{5}{c}{} \\ \cline{2-7}
(zvn) (kV)            & max. provozovací & \multicolumn{5}{c}{} \\ \hline
\CodeAfter
\begin{tikzpicture}
\coordinate (A) at ($(7-|5)!0.5!(7-|6)$) ;
\draw (A) -- (9-|A) ;
\coordinate (B) at ($(7-|3)!0.5!(A)$) ;
\coordinate (C) at ($(A)!0.5!(7-|8)$) ;
\draw (row-7-base-|B) node [anchor=base] {$400$} ; 
\draw (row-7-base-|C) node [anchor=base] {$750000$} ; 
\draw (row-8-base-|B) node [anchor=base] {$420$} ; 
\draw (row-8-base-|C) node [anchor=base] {$800$} ; 
\end{tikzpicture}
\end{NiceTabular}
\end{table}
\end{document}

Ouput of the above code

6
  • When using the example as in this answer I get: ! Fatal Package nicematrix Error: There is a problem. Maybe you have used l, c (nicematrix) and r instead of L, C and R in the (nicematrix) preamble of your environment. (nicematrix) This error is fatal. Type <return> to continue. ... l.41 \end{NiceTabular} When changing the all c into C in the line begin{NiceTabular} the result doesn't look right: i.stack.imgur.com/FHrsL.jpg
    – albert
    Sep 10 '20 at 13:04
  • You should update your TeX installation with the latest version of the package nicematrix (v. 5.3 of 2020-09-03). Sep 10 '20 at 13:22
  • OK thanks, will have a go at it.
    – albert
    Sep 10 '20 at 13:25
  • After updating and running pdflatex on it the image looked worse, but after running pdflatex twice it looked OK. (running twice is no problem and is signaled in the log file as well as it says at the end: "LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right."). When I change the $750000$ to a probably non-realistic $750750750757507507500000$ I get a box overflow for that field, but as said this value is a bit non-realistic.
    – albert
    Sep 10 '20 at 14:03
  • at first I missed your remark "You need several compilations." so I emphasized it a bit.
    – albert
    Sep 10 '20 at 14:06
2

The proposition of the OP doesn't work as expected because, with its use of \multicolumn, there are columns whose all cells are implied in \multicolumn. These columns have a natural width equal of 0 pt (and the X column of tabularx has no effect on these columns). In that case, the result given by the \multicolumn may often be surprising.

It's possible to give natural width to these columns (whose all cells are involved in \multicolumn) by adding a dummy row to the tabular:

\omit & \omit & \omit & \omit &\omit\hspace*{6mm}&\omit\hspace*{6mm}\\

That's the only thing I have modified in the code of the OP.

\documentclass[czech,12pt,oneside,openright,titlepage]{book}

\usepackage[hidelinks]{hyperref} %odkazy

\usepackage{lmodern}
\usepackage[czech]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} %cestina

%\usepackage{indentfirst} % odsazení prvního odstavce
\usepackage{parskip} % nastavení odsazení odstavců

\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor} %tabulky

\usepackage{tabularx} %tabulky na celou stránku 
\newcolumntype{C}{>{\centering}X} % Centrování sloupce

\usepackage{graphicx}
\usepackage{epstopdf} % Grafgika eps
\usepackage{float}

\usepackage{pdfpages} % PDF vkládaní

\usepackage{amsmath,amsfonts,amssymb} %matematika

%\input{mathdef.sty}

\usepackage{caption}
\usepackage{subcaption}

\usepackage[font=small,labelfont=bf,format=hang]{caption}

\usepackage[a4paper, top=2.5cm, left=2cm, right=2cm, bottom=2.5cm]{geometry} % Nastavení okrajů

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\lhead {Příručka pro pracovníky dispečerského řízení}
\rhead { \qquad 2019}
\cfoot {\thepage}
\renewcommand{\headrulewidth}{0.4pt}  %zahlavi 

%\linespread{1.5}
\setlength{\parindent}{0em}% odsazení odstavce
\setlength{\parskip}{0.5em}% mezera mezi odstavci 

\usepackage{titlesec}
\titlespacing{\chapter}{0pt}{-15pt}{10pt}
\titleformat{\chapter}[hang]{\normalfont\LARGE\bfseries}{\thechapter . \ \thispagestyle{fancy}}{0pt}{} %nastavení kapitol

\newcommand{\nadpis}[1]{\large\textbf{#1} \normalsize \medskip \\ }

\renewcommand{\figurename}{Obr.}
\renewcommand{\tablename}{Tab.} %prejmenovani


\begin{document}

\begin{table}[H]
\catcode`\-=12
\centering
\begin{tabularx}{\textwidth}{|c|c|C|C|C|C|C|c|}
\omit & \omit & \omit & \omit &\omit\hspace*{6mm}&\omit\hspace*{6mm}\\
\hline
Nízké napětí          & jmenovité        & \multicolumn{4}{c|}{0,4 / 0,23}                     & 0,50 & 0,69 \\ \cline{2-8} 
(nn) (kV)             & max. provozovací & \multicolumn{4}{c|}{0,42 / 0,241}                   & ---  & 0,73 \\ \hline
Vysoké napětí         & jmenovité        & 3           & 6          & \multicolumn{2}{c|}{10}  & 22   & 35   \\ \cline{2-8} 
(vn) (kV)             & max. provozovací & 3,6         & 7,2        & \multicolumn{2}{c|}{12}  & 25   & 37   \\ \hline
Velmi vysoké napětí   & jmenovité        & \multicolumn{2}{c|}{110} & \multicolumn{2}{c|}{220} & ---  & ---  \\ \cline{2-8} 
(vvn) (kV)            & max. provozovací & \multicolumn{2}{c|}{123} & \multicolumn{2}{c|}{245} & ---  & ---  \\ \hline
Zvláště vysoké napětí & jmenovité        & \multicolumn{3}{c|}{400}               & \multicolumn{3}{c|}{750} \\ \cline{2-8} 
(zvn) (kV)            & max. provozovací & \multicolumn{3}{c|}{420}               & \multicolumn{3}{c|}{800} \\
\hline
\end{tabularx}
\end{table}

\end{document}

Ouput of the above code

4
  • One thing I, by head, don't yet understand is why the \omit line only has 6 fields whilst the table has 8 fields. Are by default non mentioned fieds automatically added?
    – albert
    Sep 9 '20 at 20:09
  • 1
    In a tabular, when a row has less cells than the number of columns (as determinated from the preamble), there is no error. Nothing is composed for that lacking cells (the corresponding informations in the preamble are not used : it's the same thing as a \omit). Sep 9 '20 at 20:31
  • the 6mm is of course depending on the width of the the fields in the 220 / 245 column. When e.g. replacing 245 by 245245245 the column divider between the last the last columns of the last 2 lines is not anymore in the middle of the 220 / 245245245 column.
    – albert
    Sep 10 '20 at 7:56
  • 1
    You are right. If you want something really automatic, it will be much more complicated. It's possible with the extension nicematrix and some programmation. I will add an answer with that technic. Sep 10 '20 at 11:58

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.