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.

\arraystretch defines vertical spacing of tables. If I have several tables, how can I define a separate value of \arraystretch for every table? In my case, the last defined \arraystretch works for all tables.

share|improve this question
8  
I would suggest accepting answers to some of the questions you have asked. –  Seamus Feb 13 '11 at 14:18
1  
Another tip: you can use backticks ` to mark your inline code as Martin did in his edit. –  Hendrik Vogt Feb 13 '11 at 14:38
add comment

2 Answers

If you define \arraystretch direct before the table (i.e. tabular) inside a group it should only be active for this table.

\begingroup
\renewcommand*{\arraystretch}{<value>}
\begin{tabular}{...}
 ...
\end{tabular}
\endgroup

Or define your own environment:

\renewenvironment{mytabular}[1][1]{%
  \renewcommand*{\arraystretch}{#1}%
  \tabular%
}{%
  \endtabular
}

% ...

\begin{mytabular}[<stretch value>]{...}
 ...
\end{mytabular}
share|improve this answer
1  
\arraystrech is not a length ... –  Herbert Feb 13 '11 at 14:41
    
Thanks @Herbert. I changed it accordantly. –  Martin Scharrer Feb 13 '11 at 14:49
    
@MartinScharrer why do you use the * with the \renewcommand? –  Mario S. E. Apr 24 '13 at 12:52
    
@MarioS.E.: The starred version defines a "normal" macro, while the normal version defines a "long" macro which may contain \par. This is not required for \arraystretch so I used the starred version. This however is just a very minor difference and does not have a real impact here. –  Martin Scharrer Apr 24 '13 at 15:08
add comment
\documentclass{article}

\newenvironment{Tabular}[2][1]
  {\def\arraystretch{#1}\tabular{#2}}
  {\endtabular}

\begin{document}

\begin{Tabular}{ccc}
 c & c & C\\
 c & c & C
\end{Tabular}

\begin{Tabular}[3]{ccc}
 c & c & C\\
 c & c & C
\end{Tabular}

\end{document}
share|improve this answer
    
it worked. thank you. another question, e.g., how can i define a new command to use the new environment Tabular in the above example? i want to know how i can transfer parameters of \newcommand to \newenvironment. –  warem Feb 14 '11 at 9:02
    
@warem: there is no difference to the above example where I passed an argument from the environment to a command. However, to give a more explicitly answer, create an example of what you really want to do. Maybe as a new question. –  Herbert Feb 14 '11 at 9:08
    
i mean create a new command to use the Tabular environmet. e.g., \newcommand{\test}[2]{\begin{Tabular}[2]...\end{Tabular}}. it didn't work. it seemed that the parameters of test command can't be transferred to Tabular correctly. –  warem Feb 14 '11 at 9:22
    
@warem: \newcommand{\test}[2]{\begin{Tabular}{#1}#2\end{Tabular}} It depends to the menaing of #1 and #2 –  Herbert Feb 14 '11 at 9:27
    
this is what i want. thank you very much. –  warem Feb 14 '11 at 9:38
add comment

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.