0

I wrote a table with tabular in LaTeX and I would like to center a column vertically.

Here is the code that I have :

\documentclass{11pt}{article}
\usepackage{pst-all}
\usepackage{pstricks-add}

% to choose length and the left/right/center text
\usepackage{array,multirow,makecell}
\setcellgapes{1pt}
\makegapedcells
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash }b{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash }b{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash }b{#1}}

\renewcommand{\arraystretch}{1.6}
\begin{tabular}{|C{2cm}|C{2cm}|C{6cm}|C{3cm}|C{3cm}|}
\hline
$I$ & $J$ & $\textrm{Représentation graphique}$ & $I\cap J$ & $I \cup J$ \\
\hline
$]-4;5]$ & $[0;6[$ & \psset{xunit=0.4cm, yunit=0cm, yAxis=false}    %scales the picture, removes the y-axis
\begin{pspicture}(-5,0)(7,0)    
\psaxes[Dx=2, subticks=0]{->}(0,0)(-5,0)(7,0)   %creates axes
\psline[linewidth=1pt, linecolor=red]{]-]}(-4,0)(5,0)
\psline[linewidth=1pt, linecolor=blue]{[-[}(0,0)(6,0)
\end{pspicture}  & $[0;5]$ & $]-4;6[$ \\
\hline
\end{tabular}

\end{document}

what I obtain

But my intervals go over the lines, and I remarked that in fact the text is not centered vertically.

How could I fix this? I mean, I don't want to create huge lines to solve my problem.

1

1 Answer 1

0

(1) The table, as it is, overflows the width of the text. It's easy to fix using the tabularx package which calculates the width of the selected columns to fit the table to the width of the text.

(2) The pspicture can be shift using the optional [shift=<number>].

b

% !TeX TS-program =xelatex 
    
\documentclass[11pt]{article}
\usepackage{pst-all}
\usepackage{pstricks-add}
    
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash }b{#1}}

\usepackage{tabularx}% added <<<<<<<<<
\newcolumntype{W}{>{\centering\arraybackslash}X} % added <<<<<<<<<

\usepackage{showframe} % ONLY to show the magins <<<<<<<<<
\begin{document}    
\renewcommand{\arraystretch}{1.8}   

\noindent\begin{tabularx}{\textwidth}{|W|W|C{6cm}|W|W|}
\hline
$I$ & $J$ & Représentation graphique & $I\cap J$ & $I \cup J$ \\
\hline
$]-4;5]$ & $[0;6[$ & \psset{xunit=0.4cm, yunit=0cm, yAxis=false}    %scales the picture, removes the y-axis
\begin{pspicture}[shift=0.3](-5,0)(7,0)    
    \psaxes[Dx=2, subticks=0]{->}(0,0)(-5,0)(7,0)   %creates axes
    \psline[linewidth=1pt, linecolor=red]{]-]}(-4,0)(5,0)
    \psline[linewidth=1pt, linecolor=blue]{[-[}(0,0)(6,0)
\end{pspicture}  & $[0;5]$ & $]-4;6[$ \\[0.7ex]% increase the height of the row
\hline
\end{tabularx}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .