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 am familiar with the newenvironment command, but I was wondering, how do I carry on the parameters that are used between [ ], i.e [bht!]?

I want to make a newfig and a newtab environment that will take care of some stuff that I don't want to redo everytime, i.e. center a figure or set text size to small.. I am lazy, and this can improve the readability of my tex document as well.

I know I can define them as normal parameters like this :

\newenvironment{tableC}[2]
{\begin{table}[#1#2]\begin{center}}
{\end{center}\end{table}}

but these parameters are not always present, and do not necessarily have a default value. For example, the ! parameter has no default equivalent (or does it?). What can I do from this point?

EDIT: Using floats, I was able to do what I needed. Here is how I did it for tables :

\usepackage{float}
\newfloat{tableC}{tbp}{lop}[chapter]
\floatname{tableC}{Table}
\floatevery{tableC}{\centering}
share|improve this question
    
Not particularly related, but R has a nice feature, where you can put "..." in the list of arguments a function takes, and then within the function use "..." to pass that list of arguments to other functions within it. –  Seamus Oct 7 '10 at 16:08
add comment

2 Answers

up vote 7 down vote accepted

Use the float package

\usepackage{float}
\restylefloat{figure}
\floatevery{figure}{\centering}
\floatplacement{figure}{bht}

It also provides a \newfloat command.

share|improve this answer
    
Nice and clean! –  Juan A. Navarro Oct 8 '10 at 10:59
add comment

Would it work if you simply define a new environment with an optional argument and a sensible default?

\newenvironment{newtable}[1][hbt]{\table[#1]\centering}{\endtable}

Then you can write

\begin{newtable}
... stuff ...
\end{newtable}

\begin{newtable}[hbt!]
... stuff ...
\end{newtable}

\begin{newtable}[H]
... stuff ...
\end{newtable}
share|improve this answer
    
Yeah, that works. I remember trying to do this and not being able to, must have messed up somewhere :D –  levesque Oct 13 '10 at 15:24
    
To be fair, I also misread your question the first time you posted it, and I was going to suggest some wild TeX-ish hack. Luckily, the problem was actually quite simple! –  Juan A. Navarro Oct 13 '10 at 15:26
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.