2

i'm trying to draw a table with the first cell splitted by a diagonal border. But since my headings have 2 lines, the other cells also have 2 lines, and then the borders are incomplete, generating "gaps" over the table, as well the cells are not centered at the middle of the cell, becoming an ugly format.

I'm using slashbox package, and compiling with Overleaf.

Can someone help?

Thanks!! Eduardo.

\usepackage{slashbox}
\begin{document}
\begin{table}[H]
\begin{center}
\caption{Classificação de Marchal: as estruturas de mercado diferenciadas também por fatores associados ao comportamento dos agentes a natureza dos produtos.}
\label{table:rossetti}
\begin{tabular}{|l||*{3}{c|}}\hline
\backslashbox{\textbf{Procura}}{\textbf{Oferta}}
& \textbf{Um so vendedor} & \begin{tabular}[c]{@{}c@{}}\textbf{Pequeno numero}\\ \textbf{de vendedores}\end{tabular} & \begin{tabular}[c]{@{}c@{}}\textbf{Grande numero}\\ \textbf{de vendedores}\end{tabular} \\ \hline
Um só comprador\\ &Monopolio bilateral & Quase monopsonio & Monopsonio\\\hline
Pequeno numero de\\compradores &Quase monopolio &Oligopolio bilateral &Oligopsonio\\\hline
Grande numero de\\compradores &Monopolio &Oligopolio &Concorrencia perfeita\\ \hline
\end{tabular}
\end{center}
\end{table}
\end{document}
2
  • 2
    Welcome to TeX.SE! Which documentclass do you use and can you please add an screenshot of your result to your question?
    – Mensch
    Aug 5 '21 at 19:17
  • You're right, but I couldn't find where to upload a screenshot. I only find with a hyperlink. Thanks. Aug 6 '21 at 21:38
2

I propose this solution with diagbox and makecell. To make the table fit text width, I suggest loading the geometry package. I also loaded caption to have a more decent spacing between caption and table. Note that you shouldn't use the center environment within table, as it adds unwanted vertical spacing – use \centering instead.

\documentclass{article}
\usepackage{geometry}
\usepackage{diagbox}
\usepackage{caption, makecell}

\begin{document}

\begin{table}[!h]
\renewcommand{\theadfont}{\normalsize\bfseries}
\centering
\caption{Classificação de Marchal: as estruturas de mercado diferenciadas também por fatores associados ao comportamento dos agentes a natureza dos produtos.}
\label{table:rossetti-1}
\begin{tabular}{|l||*{3}{c|}}\hline
\diagbox[height=30pt, width=90pt]{\textbf{Procura}}{\textbf{Oferta}}
& \thead{Um so vendedor} & \thead{Pequeno numero \\ de vendedores} & \thead{Grande numero\\ de vendedores} \\ \hline
\Gape[6pt]{Um só comprador} & Monopolio bilateral & Quase monopsonio & Monopsonio\\\hline
\makecell[l]{Pequeno numero \\ de compradores} & Quase monopolio &Oligopolio bilateral &Oligopsonio\\\hline
\makecell[l]{Grande numero \\ de compradores} &Monopolio &Oligopolio &Concorrencia perfeita\\ \hline
\end{tabular}
\end{table}

\end{document} 

enter image description here

3
  • Thanks, Bernard! Your solution is very good! But the diagonal border in my Overleaf are not well aligned to the corner, and I don't know why your compilation is ok, and not for me. Aug 6 '21 at 21:36
  • Perhaps because Overleaf is not really up-to-date. I found the values of the height and width arguments by trial and error, so probably you should play a bit with these values.
    – Bernard
    Aug 6 '21 at 22:39
  • Yes, my friend, you're right! I adjusted and now it looks perfect!!! Next step is to look for a solution on how to set the font size to 10 (i'm using Arial 12). Thanks again! Aug 7 '21 at 0:50
0

With {NiceTabular} of nicematrix, which has a built-in command \diagbox.

\documentclass{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{nicematrix}

\begin{document}

\begin{table}[!h]
\centering
\caption{Classificação de Marchal: as estruturas de mercado diferenciadas também por fatores associados ao comportamento dos agentes a natureza dos produtos.}
\label{table:rossetti-1}
\begin{NiceTabular}{|l||*{3}{c|}}\hline
\RowStyle{\bfseries}
\diagbox{\bfseries Procura}{\bfseries Oferta\;}
& Um so vendedor & \Block{}{Pequeno numero \\ de vendedores} & \Block{}{Grande numero\\ de vendedores} \\ \hline
\RowStyle[cell-space-limits=6pt]{}
Um só comprador & Monopolio bilateral & Quase monopsonio & Monopsonio\\\hline
\Block{}{Pequeno numero \\ de compradores} & Quase monopolio &Oligopolio bilateral &Oligopsonio\\\hline
\Block{}{Grande numero \\ de compradores} &Monopolio &Oligopolio &Concorrencia perfeita\\ \hline
\end{NiceTabular}
\end{table}

\end{document} 

Output of the above code

3
  • 1
    Thank you Pantigny! It seems to be a nice solution, but despite I just copy/paste your code, Overleaf stopped compiling. It may be a package problem. I'm using XeLaTex compilator, because I must use Arial font. Thanks anyway!! Aug 6 '21 at 21:37
  • @Eduardo Rosa Kras Borges: Overleaf has not the latest version of nicematrix. You should upload the latest version of the file nicematrix.sty in the repertory of your Overleaf project. You can find that file on the SVN server of TeXLive: www.tug.org/svn/texlive/trunk/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty Aug 7 '21 at 7:32
  • Very nice! It works perfectly! Thanks for your precious contribution!! Aug 9 '21 at 12:50

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.