Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a problem with my table. I should put a big text in a cell. it should be multi line. How can I do that:

\begin{table}[H]
\centering % used for centering table
\begin{tabular}{c c c c c} 
\hline 
\\
Case & Entscheidungsbäume & Neuronale Netze & kNN & SVM \\ 
\hline\hline % inserts single horizontal line
\\
Accuracy in general & ** & *** & ** & **** \\ % 
Speed of learning with 
respect to number of 
attributes and the number of 
instances  & *** &* & **** & * \\
3 & 31 & 25 & 415 \\
4 & 35 & 144 & 2356 \\
5 & 45 & 300 & 556 \\ [1ex] % 
\end{tabular}
\caption{Nonlinear Model Results} % title of Table
\label{table:nonlin} % is used to refer this table in the text

\end{table}

thanks

share|improve this question
    
Possible duplicate: tex.stackexchange.com/q/169262/34120 –  Timmy Aug 4 at 14:19

2 Answers 2

up vote 4 down vote accepted

I suggest you (a) switch from a tabular to a tabularx environment, (b) set the overall width of the tabularx environment to \textwidth, and (c) use a (modified form of) the X column type for the first column. Doing so tells LaTeX to calculate the width of the first column as the difference between \textwidth and the sum of the widths of the other columns.

In addition, consider doing your readers a favor by using the line-drawing macros of the booktabs package instead of the basic-LaTeX \hline instruction.

enter image description here

\documentclass[a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman,english]{babel}
\usepackage{tabularx}  % for 'tabularx' environment and 'X' column type
\usepackage{ragged2e}  % for '\RaggedRight' macro (allows hyphenation)
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X} 
\usepackage{booktabs}  % for \toprule, \midrule, and \bottomrule macros 

\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{@{} Y c c c c @{}} % use 'Y' for first column
\toprule
Case & Entscheidungsbäume & Neuronale Netze & kNN & SVM \\
\midrule
Accuracy in general & ** & *** & ** & **** \\ \addlinespace
Speed of learning with
respect to number of
attributes and number of
instances  & *** &* & **** & * \\ \addlinespace
3 & 31 & 25 & 415 \\
4 & 35 & 144 & 2356 \\
5 & 45 & 300 & 556 \\ 
\bottomrule
\end{tabularx}
\caption{Nonlinear Model Results} 
\label{table:nonlin}
\end{table}
\end{document}

Addendum to address the OP's follow-up questions:

  1. My advice would be to avoid double lines; they reek of the 1970s and 1980s... If you want to make the lines created by \toprule and \bottomrule a bit thicker, you can do so by changing the value of the parameter \heavyrulewidth. Its default value is 0.08em; try, say, \setlength\heavyrulewidth{0.1em} and see if you like the result. The width of \midrule is governed by the parameter \lightrulewidth (default value: 0.05em); see if \setlength\lightrulewidth{0.625em} works for you. By the way, if you insist on having two consecutive rules, \toprule\toprule, \midrule\midrule, etc will get the job done...

  2. I assume that by having "stars in the middle of each cell" you mean that the asterisks should be centered vertically. (The asterisks are, of course, already centered horizontally.) In this regard my advice is, yet again, "don't do it." :-) Instead, you may want to consider making columns 2 and 3 narrower by introducing line breaks in the headers. By making columns 2 and 3 less wide, column 1 automatically becomes wider, and the lengthy text in one of the cells now fits in three rows instead of five. The effect is shown below -- I think that it's no longer useful to think about repositioning the asterisks. (If you still insist on vertically centering the asterisks, issue the instruction \renewcommand{\tabularxcolumn}[1]{m{#1}} after loading the tabularx package and before setting up the Y column type...)

Just for fun I've also augmented the values of \heavyrulewidth and \lightrulewidth by 25% in the following image, per the discussion in the first bullet point.

enter image description here

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman,english]{babel}
\usepackage{tabularx}  % for 'tabularx' environment and 'X' column type
\usepackage{ragged2e}  % for '\RaggedRight' macro (allows hyphenation)
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X} 
\usepackage{booktabs}  % for \toprule, \midrule, and \bottomrule macros 

\setlength\heavyrulewidth{0.1em}
\setlength\lightrulewidth{0.0625em}
\begin{document}\pagestyle{empty}
\begin{table}
\begin{tabularx}{\textwidth}{@{} Y c c c c @{}} % use 'Y' for first column
\toprule
Case & Entscheidungs- & Neuronale & kNN & SVM \\ %% new: line breaks in two of the header cells
& bäume & Netze\\
\midrule
Accuracy in general & ** & *** & ** & **** \\ \addlinespace
Speed of learning with
respect to number of
attributes and number of
instances  & *** &* & **** & * \\ \addlinespace
3 & 31 & 25 & 415 \\
4 & 35 & 144 & 2356 \\
5 & 45 & 300 & 556 \\ 
\bottomrule
\end{tabularx}
\caption{Nonlinear Model Results} 
\label{table:nonlin}
\end{table}
\end{document}
share|improve this answer
    
thank you for your answer, I have two questions (1) how can I have double thick line instead of one thick line? and (2) I want to have stars in the middele of each cells? how can I modified this beatiful code to do that? –  Kaja Aug 4 at 16:30
    
@Kaja - I've posted an addendum to address your follow-up questions. As you'll see, I suggest not adjusting the vertical positions of the asterisks but to redistribute the widths of columns 1, 2, and 3 in a straightforward way. By making column 1 wider, the lengthy material in one of the cells no longer occupies 5 but only 3 rows. If you make this change, I believe it's no longer necessary or useful to fiddle with the vertical position of the asterisks. –  Mico Aug 4 at 18:00

The p attribute should help.

\begin{tabular}{p{3cm} c c c c} 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.