1

The diagonal does not touch the corner. Thank you for any help.

enter image description here

% Table generated by Excel2LaTeX from sheet 'Planilha1'
\begin{table}[htbp]
\footnotesize
\centering
\captionsetup{width=0.75\textwidth}
\caption{Exemplo de configurações geradas aleatoriamente para teste de multiplexação, indicando 
os valores em kg das cargas aplicadas em cada região.}
\begin{tabular}{c C{1.5cm} C{1.5cm} C{1.5cm} C{1.5cm} C{1.5cm}}
\toprule
\multicolumn{1}{c|}{\diagbox[innerwidth=3cm]{\textbf{Região}}{\textbf{Config.}}} & \multirow{2}[2]{*}{\textbf{1}} & \multirow{2}[2]{*}{\textbf{2}} & \multirow{2}[2]{*}{\textbf{3}} & \multirow{2}[2]{*}{\textbf{4}} & \multirow{2}[2]{*}{\textbf{5}}
\\
\multicolumn{1}{c|}{} &       &       &       &       &  \\
\midrule
1     & 0,5    & 0,5   & 0,0   & 0,0   & 0,0 \\
2     & 0,0    & 1,0   & 0,0   & 0,5   & 1,0\\
3     & 0,5    & 1,5   & 1,0   & 2,0   & 0,0 \\
4     & 0,0    & 0,0   & 0,5   & 0,0   & 1,0 \\
5     & 0,0    & 0,5   & 0,5   & 0,0   & 0,0 \\
6     & 1,5    & 0,5   & 1,0   & 1,0   & 0,0 \\
7     & 2,0    & 1,0   & 0,0   & 0,5   & 0,0 \\
8     & 0,5    & 1,0   & 0,0   & 0,0   & 0,5 \\
9     & 0,0    & 0,0   & 1,0   & 0,0   & 1,5 \\
10    & 2,0    & 0,5   & 0,5   & 1,0   & 0,0 \\
\bottomrule
\end{tabular}%
\label{tab:tab1}%
\end{table}%
7
  • 1
    As always on this site please provide a full, but minimal, example that others can copy and test as is. Here we have to add a lot of stuff before we can even test your code – daleif Jul 7 '20 at 17:28
  • Sorry for this example, but if i provide a minimal example of this table, the code works normaly. My problem is only if i test this code. – diogo lugarini Jul 7 '20 at 17:49
  • 1
    That does not make sense. Either the code works or it doesn't. If you cannot make a minimal example showing the problem, but the problem still exists in your real document, then there is something in the real document you haven't added. As we don't know your code, we cannot help much – daleif Jul 7 '20 at 17:52
  • You're right. I misunderstood your previous comment. – diogo lugarini Jul 7 '20 at 17:58
  • Not directly related to the issue but please be aware that the horizontal llines from the booktabs package were designed to be used without vertical lines. – leandriis Jul 7 '20 at 17:59
3

Here are two versions of your table. In the first one, I have removed the empty line as well as the \multirow commands. This will improve the diagbox output. However, there will still be small white spaces around the intersections as the horizontal lines from the booktabs package are desigend to be used without vertical lines.

Personally, I would suggest using a table similar to the second example. With this solutions, there is no need for vertical or diagonal lines. I have also changed the column specifiers since I could nt see a reason to make the table columns wider than they would naturally be.

enter image description here

\documentclass{article}
\usepackage{booktabs}
\usepackage{diagbox}
\usepackage{caption}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}

% Table generated by Excel2LaTeX from sheet 'Planilha1'
\begin{table}[htbp]
\footnotesize
\centering
\captionsetup{width=0.75\textwidth}
\caption{Exemplo de configurações geradas aleatoriamente para teste de multiplexação, indicando 
os valores em kg das cargas aplicadas em cada região.}
\begin{tabular}{c C{1.5cm} C{1.5cm} C{1.5cm} C{1.5cm} C{1.5cm}}
\toprule
\multicolumn{1}{c|}{\diagbox[innerwidth=3cm]{\textbf{Região}}{\textbf{Config.}}} & \textbf{1} & \textbf{2} &\textbf{3} & \textbf{4} & \textbf{5}
\\
%\multicolumn{1}{c|}{} &       &       &       &       &  \\
\midrule
1     & 0,5    & 0,5   & 0,0   & 0,0   & 0,0 \\
2     & 0,0    & 1,0   & 0,0   & 0,5   & 1,0\\
3     & 0,5    & 1,5   & 1,0   & 2,0   & 0,0 \\
4     & 0,0    & 0,0   & 0,5   & 0,0   & 1,0 \\
5     & 0,0    & 0,5   & 0,5   & 0,0   & 0,0 \\
6     & 1,5    & 0,5   & 1,0   & 1,0   & 0,0 \\
7     & 2,0    & 1,0   & 0,0   & 0,5   & 0,0 \\
8     & 0,5    & 1,0   & 0,0   & 0,0   & 0,5 \\
9     & 0,0    & 0,0   & 1,0   & 0,0   & 1,5 \\
10    & 2,0    & 0,5   & 0,5   & 1,0   & 0,0 \\
\bottomrule
\end{tabular}%
\label{tab:tab1}%
\end{table}%


\begin{table}[htbp]
\centering
\caption{Exemplo de configurações geradas aleatoriamente para teste de multiplexação, indicando 
os valores em kg das cargas aplicadas em cada região.}
\begin{tabular}{cccccc}
\toprule
Região & \multicolumn{5}{c}{Config.} \\\cmidrule{2-6}
 & 1 & 2 & 3 & 4 & 5 \\
\midrule
1     & 0,5    & 0,5   & 0,0   & 0,0   & 0,0 \\
2     & 0,0    & 1,0   & 0,0   & 0,5   & 1,0 \\
3     & 0,5    & 1,5   & 1,0   & 2,0   & 0,0 \\
4     & 0,0    & 0,0   & 0,5   & 0,0   & 1,0 \\
5     & 0,0    & 0,5   & 0,5   & 0,0   & 0,0 \\
6     & 1,5    & 0,5   & 1,0   & 1,0   & 0,0 \\
7     & 2,0    & 1,0   & 0,0   & 0,5   & 0,0 \\
8     & 0,5    & 1,0   & 0,0   & 0,0   & 0,5 \\
9     & 0,0    & 0,0   & 1,0   & 0,0   & 1,5 \\
10    & 2,0    & 0,5   & 0,5   & 1,0   & 0,0 \\
\bottomrule
\end{tabular}%
\label{tab:tab1}%
\end{table}%

\end{document}
1
2

You can use {NiceTabular} of nicematrix which a built-in \diagbox command which draws the rule with Tikz. However, we will have the problem of the small vertical rule. You can draw it with Tikz using the PGF/Tikz nodes created under the tabular by nicematrix.

\documentclass{article}
\usepackage[portuges]{babel}
\usepackage{array}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{caption}
\usepackage{nicematrix}
\usepackage{booktabs}
\usepackage{tikz}

\begin{document}

\begin{table}[htbp]
\footnotesize
\centering
\captionsetup{width=0.75\textwidth}
\caption{Exemplo de configurações geradas aleatoriamente para teste de multiplexação, indicando 
os valores em kg das cargas aplicadas em cada região.}
\begin{NiceTabular}{*{6}{c}}[columns-width=1.5cm]
\toprule
\diagbox{Região}{Config.} &  1 &  2 &  3 &  4 &  5 
\rule[-2mm]{0pt}{5mm}
\\
\midrule
1     & 0,5    & 0,5   & 0,0   & 0,0   & 0,0 \\
2     & 0,0    & 1,0   & 0,0   & 0,5   & 1,0 \\
3     & 0,5    & 1,5   & 1,0   & 2,0   & 0,0 \\
4     & 0,0    & 0,0   & 0,5   & 0,0   & 1,0 \\
5     & 0,0    & 0,5   & 0,5   & 0,0   & 0,0 \\
6     & 1,5    & 0,5   & 1,0   & 1,0   & 0,0 \\
7     & 2,0    & 1,0   & 0,0   & 0,5   & 0,0 \\
8     & 0,5    & 1,0   & 0,0   & 0,0   & 0,5 \\
9     & 0,0    & 0,0   & 1,0   & 0,0   & 1,5 \\
10    & 2,0    & 0,5   & 0,5   & 1,0   & 0,0 \\
\bottomrule
\CodeAfter
\tikz \draw (1-|2) -- (2-|2) ;
\end{NiceTabular}%
\label{tab:tab1}%
\end{table}%

\end{document}

Output of the above code

However, the result is rather poor. Many people will suggest you to use booktabs in the spirit of booktabs (with no diagonal and no vertical rule).

1
1

Here is a solution using matrix of TikZ.

\documentclass{article}
\usepackage{tikz,lipsum}
\usetikzlibrary{matrix}
\begin{document}
\lipsum[2]
\begin{center}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,
nodes in empty cells,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={minimum height=5mm,minimum width=16mm,anchor=center},
row 1/.style={nodes={minimum height=9mm,font=\bfseries}},
column 1/.style={nodes={minimum width=3.5cm}},
]{
      & 1      &  2    & 3     & 4     & 5   \\ 
1     & 0,5    & 0,5   & 0,0   & 0,0   & 0,0 \\
2     & 0,0    & 1,0   & 0,0   & 0,5   & 1,0 \\
3     & 0,5    & 1,5   & 1,0   & 2,0   & 0,0 \\
4     & 0,0    & 0,0   & 0,5   & 0,0   & 1,0 \\
5     & 0,0    & 0,5   & 0,5   & 0,0   & 0,0 \\
6     & 1,5    & 0,5   & 1,0   & 1,0   & 0,0 \\
7     & 2,0    & 1,0   & 0,0   & 0,5   & 0,0 \\
8     & 0,5    & 1,0   & 0,0   & 0,0   & 0,5 \\
9     & 0,0    & 0,0   & 1,0   & 0,0   & 1,5 \\
10    & 2,0    & 0,5   & 0,5   & 1,0   & 0,0 \\
};
\draw[teal] 
(m-1-1.north west)--(m-1-1.south east)
(m-1-1.north east)--(m-1-1.south east)
(m-1-1.north west)--(m-1-6.north east)
(m-1-1.south west)--(m-1-6.south east)
(m-11-1.south west)--(m-11-6.south east)
(m-1-1.south west) node[above right]{\bfseries Religion}
(m-1-1.north east) node[below left]{\bfseries Config.};
\end{tikzpicture}
\end{center}
\lipsum[3]  
\end{document}  
1

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.