1

I'm writing a table but in some rows the text exceeds vertically the limit. How can I fix it? thanks.

That is my code:

\documentclass[a4paper,12pt]{article}[12pt] 
\usepackage{amsbsy}
\usepackage{amsmath}
\usepackage{pbox}
\usepackage{fancyhdr}
\usepackage{cancel}
\usepackage{tabularx} 
\usepackage{booktabs} 
\usepackage{multirow}
\usepackage{longtable} 
\usepackage{natbib} 
\usepackage{arydshln}
\usepackage{tikz}


\usepackage{subfig}                        

\usepackage{xcolor}
\usepackage{amsmath} 
\usepackage{amssymb}
\usepackage{mathrsfs} 

\linespread{1.5}    


\frenchspacing 

\newcommand{\abs}[1]{\lvert#1\rvert}



 \usepackage{multicol}



 \usepackage[a4paper,top=1.0cm,bottom=1.0cm,left=1.0cm,right=1.0cm]{geometry}


 \newcommand{\cuthere}{%
 \noindent
 \raisebox{-2.8pt}[0pt][0.75\baselineskip]{\small\ding{34}}
 \unskip{\tiny\dotfill}
 }

 \newcommand{\makenonemptybox}[2]{%
   \par\nobreak\vspace{\ht\strutbox}\noindent
   \fbox{%
     \parbox[c][\dimexpr#1-2\fboxsep][t]{\dimexpr\linewidth-2\fboxsep}{
       \hrule width \hsize height 0pt
       #2
     }%
   }%
   \par\vspace{\ht\strutbox}
 }


\begin{document}



\makenonemptybox{3.2in}{
\colorbox{white}{}
\noindent \textbf{}



\noindent\begin{minipage}{0.60\linewidth}
\begin{tabular}{c|l}
  $x$  & $y $                      \\
  \hline
   $\dfrac{1}{2}$  &  \\
    \hdashline
   $1$  & \\
    \hdashline  
  $\dfrac{3}{2}$  &  \\
\hdashline
\end{tabular}
 \end{minipage}%
\begin{minipage}{0.4\linewidth}
 \centering

 \includegraphics[width=1.0\linewidth]{image.pdf}
\end{minipage}


}

\end{document}






 \usepackage[a4paper, margin=1.0cm]{geometry}

  \newcommand{\cuthere}{%
  \noindent
  \raisebox{-2.8pt}[0pt][0.75\baselineskip]{\small\ding{34}}
  \unskip{\tiny\dotfill}
  }

  \newcommand{\makenonemptybox}[2]{%
    \par\nobreak\vspace{\ht\strutbox}\noindent
    \fbox{%
      \parbox[c][\dimexpr#1-2\fboxsep][t]{\dimexpr\linewidth-2\fboxsep}{
        \hrule width \hsize height 0pt
        #2
      }%
    }%
    \par\vspace{\ht\strutbox}
  }

  \usepackage{cellspace}
  \setlength{\cellspacetoplimit}{4pt}
  \setlength{\cellspacebottomlimit}{4pt}

 \begin{document}

 \makenonemptybox{3.2in}{
 \colorbox{white}{}
 \noindent \textbf{}

 \noindent\begin{minipage}{0.60\linewidth}
  \begin{tabular}{ >{$}Sc<{$}|l}
 $ x $  & $ y = 3x+2 $ \\
   \hline
 $\dfrac{1}{2}$  & $3 \cdot \dfrac{1}{2}  + 2$  \\
     \hdashline
   1 & \\
     \hdashline
  \dfrac{3}{2} \\
 \hdashline
 \end{tabular}
  \end{minipage}%
 \begin{minipage}{0.4\linewidth}
  \centering

  \includegraphics[width=1.0\linewidth]{image.pdf}
 \end{minipage}
 }

 \end{document}
  • you have loaded the longtable package which allows multi-page tables but not used it. Also unrelated do not use epsfig for any document less than 30 years old. – David Carlisle Jan 4 at 22:04
  • @davidCarlisle ok I'll delete the package epsfig from my code. – ryuk Jan 4 at 22:21
2

A solution with package cellspace, which enables you to define a minimal vertical spacing at the top and bottom of cells in columns with specifier prefixed with the letter S (or C if you load siunitx, since this package already defines an S column type for another purpose).

\documentclass[a4paper,12pt, demo]{article}[12pt]

\usepackage{amsbsy, amssymb}
\usepackage{mathrsfs}
\usepackage{amsmath}
\usepackage{pbox}
\usepackage{fancyhdr}
\usepackage{cancel}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{natbib}
\usepackage{arydshln}
\usepackage{tikz}
\usepackage{subfig}
\usepackage{xcolor}

\linespread{1.5}

\frenchspacing

\newcommand{\abs}[1]{\lvert#1\rvert}

\usepackage{floatflt,epsfig}
 \usepackage{multicol}
 \usepackage[a4paper, margin=1.0cm]{geometry}

 \newcommand{\cuthere}{%
 \noindent
 \raisebox{-2.8pt}[0pt][0.75\baselineskip]{\small\ding{34}}
 \unskip{\tiny\dotfill}
 }

 \newcommand{\makenonemptybox}[2]{%
   \par\nobreak\vspace{\ht\strutbox}\noindent
   \fbox{%
     \parbox[c][\dimexpr#1-2\fboxsep][t]{\dimexpr\linewidth-2\fboxsep}{
       \hrule width \hsize height 0pt
       #2
     }%
   }%
   \par\vspace{\ht\strutbox}
 }

 \usepackage{cellspace}
 \setlength{\cellspacetoplimit}{4pt}
 \setlength{\cellspacebottomlimit}{4pt}

\begin{document}

\makenonemptybox{3.2in}{
\colorbox{white}{}
\noindent \textbf{}

\noindent\begin{minipage}{0.60\linewidth}
 \begin{tabular}{ >{$}Sc<{$}|l}
 x & y \\
  \hline
   \dfrac{1}{2} & \\
    \hdashline
  1 & \\
    \hdashline
 \dfrac{3}{2} \\
\hdashline
\end{tabular}
 \end{minipage}%
\begin{minipage}{0.4\linewidth}
 \centering

 \includegraphics[width=1.0\linewidth]{image.pdf}
\end{minipage}
}

\end{document} 

enter image description here

  • Thanks a lot! One little question...if i have to add some formula I can see the pdf but there's an error (Extra }, or forgotten $ }, Missing } inserted }). How can I fix it? I post a new code under mine in the question...thanks a lot! – ryuk Jan 4 at 22:57
  • Could you post the corresponding code, or a link to? I suppose my code compiles without a problem for you? – Bernard Jan 4 at 23:01
  • ok \begin{tabular}{ >{$}Sc<{$}|l} $ x $ & $ y = 3x+2 $ \\ \hline $\dfrac{1}{2}$ & $3 \cdot \dfrac{1}{2} + 2$ \\ \hdashline 1 & \\ \hdashline \dfrac{3}{2} \\ \hdashline \end{tabular} – ryuk Jan 4 at 23:09
  • I've modified only the table because I need to add some formulas. – ryuk Jan 4 at 23:10
  • 1
    You didn't see that passing in math mode in the first column took place at the preamble level (>{$}c<{$} does just this). So if you have only formulæ in your table (except perhaps headers), use this code (no $ inthe body of the tabel!): \begin{tabular}{>{$}Sc<{$}|>{$}Sl<{$}} x & y = 3x+2 \\ \hline \dfrac{1}{2} & 3 \cdot \dfrac{1}{2} + 2 \\ \hdashline 1 & \\ \hdashline \dfrac{3}{2} \\ \hdashline \end{tabular}. – Bernard Jan 4 at 23:20

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.