If you would like to center all tabular environments, I would recommend to create your own environment with a different name, which calls tabular. You could use that instead of redefining tabular itself.
But no problem, this can be done. Just use \renewenvironment
, for example:
\let\originaltabular\tabular
\let\endoriginaltabular\endtabular
\renewenvironment{tabular}[1]{%
\begingroup%
\centering%
\originaltabular{#1}}%
{\endoriginaltabular\endgroup}
This as addition to your first try redefining tabular.
You could redefine the floating table environment very similar:
\let\originaltable\table
\let\endoriginaltable\endtable
\renewenvironment{table}[1][ht]{%
\originaltable[#1]
\centering}%
{\endoriginaltable}
You could also use etoolbox to patch the table environment or append \centering
to the definition this way:
\makeatletter
\g@addto@macro{\table}{\centering}
\makeatother
or
\expandafter\def\expandafter\table\expandafter{\table\centering}
Just use:
\raggedright
right after \begin{document}
The flushleft
environment effectively sets text in a ragged right list environment. It is defined as:
\def\flushleft{\trivlist \raggedright\item\relax}
\def\endflushleft{\endtrivlist}
The \raggedright
command does the actual work:
\def\raggedright{%
\let\\\@centercr\@rightskip\@flushglue \rightskip\@rightskip
\leftskip\z@skip
\parindent\z@}
Setting text this way will lead to some ugly looking lines. The ragged2e
package provides the \RaggedRight
command (and corresponding) FlushLeft
environment that solves some of these problems. I would recommend using it instead of just \raggedright
.
To see the differences between \raggedright
and \RaggedRight
here's a small sample document:
\documentclass{article}
\usepackage[english]{babel}
\usepackage[margin=1in]{geometry}
\usepackage{hyphenat}
\usepackage{ragged2e}
\usepackage{blindtext}
\begin{document}
\begin{minipage}[t]{.4\textwidth}
\textbf{raggedright with no hyphenation}\par
\raggedright
\blindtext
\end{minipage}
\hfill
\begin{minipage}[t]{.4\textwidth}
\textbf{RaggedRight with hyphenation}\par
\RaggedRight
\blindtext
\end{minipage}
\end{document}
![output of code](https://i.stack.imgur.com/anGCr.png)
Both \raggedright
and \RaggedRight
set the paragraph indent to zero. With ragged2e
this is controllable with the length \RaggedRightParindent
which can be set to equal the regular \parindent
in the following way:
\setlength{\RaggedRightParindent}{\parindent}
To do this with regular \raggedright
you could do the following:
\usepackage{etoolbox}
\newlength{\rrindent}
\setlength{\rrindent}{\parindent}
\apptocmd{\raggedright}{\setlength{\parindent}{\rrindent}}{}{}
Best Answer