Suppose I want to left justify all my tables to a certain vertical line (MWE):
\documentclass[11pt,a4paper,oneside]{memoir}
\pagestyle{plain}
\usepackage{fontspec}
%\usepackage{changepage}
\setmainfont[Mapping=tex-text]{Liberation Serif}
\setsansfont[Mapping=tex-text]{Liberation Sans}
\setmonofont[Mapping=tex-text]{Liberation Mono}
\newcommand{\leftpadding}{1cm}
\begin{document}
\chapter{}
All Gaul is divided into three parts, one of which the Belgae inhabit, the Aquitani another, those who in their own language are called Celts, in our Gauls, the third. All these differ from each other in language, customs and laws. The river Garonne separates the Gauls from the Aquitani; the Marne and the Seine separate them from the Belgae.
\medskip\begin{adjustwidth}{\leftpadding}{0cm}
\raggedright{Caption}\\
\renewcommand*{\arraystretch}{1.4}
\footnotesize\begin{tabular}[c]{|c|c|}
\hline
{Alfa}
& {Bravo}
\\\hline
{Charlie}
& {Delta}
\\\hline
\end{tabular}
\end{adjustwidth}
\bigskip
Of all these, the Belgae are the bravest, because they are furthest from the civilization and refinement of [our] Province, and merchants least frequently resort to them, and import those things which tend to effeminate the mind.
\medskip\begin{adjustwidth}{\leftpadding}{0cm}
\raggedright{Another Caption}\\
\renewcommand*{\arraystretch}{1.4}
\footnotesize\begin{tabular}[c]{|c|c|}
\hline
{Longer Echo}
& {Long Foxtrot}
\\\hline
{Golf}
& {Hotel}
\\\hline
\end{tabular}
\end{adjustwidth}
\bigskip
They are the nearest to the Germans, who dwell beyond the Rhine, with whom they are continually waging war; for which reason the Helvetii also surpass the rest of the Gauls in valor.
\end{document}
This solution works, but I want more flexibility. How, for instance, am I to redefine \leftpadding
to center all the tables at once? It should be possible, at least in two passes. The option of right justifying wouldn't hurt, too. Entirely different solutions to the same purpose are also welcome.
Best Answer
Though I don't quite get what you want, here is a solution (which hopefully fits your needs) using the
pgfkeys
-package. I made the captions in a way, that they can be labeled (using thelabel=
key) but they don't use the\caption
command internally. Also it doesn't use your command\leftpadding
but thepadding
-key.EDIT: Note that I have slightly altered the above code.
Usage of the
placedtabular
-environment is just like a normaltabular
except, that in the optional argument you can use a comma seperatedkey=value
syntax. The following keys are alailable:stretch
: the value used forarraystretch
place
: the placement of the table. Available areleft
,right
andmiddle
padding
: the space to the left or right margin withplace=left
orplace=right
, respectivelycaption
: the caption used for the tablescaption
: the table-name for the\listoftables
, if not usedcaption
is used. Ifcaption
is not used, this doesn't have any effect.label
: the label used for referencing the tableWhen you use one of these keys in a
placedtabular
-environment, the effects are only local and don't affect any other table set with this environment.From the aforementioned keys
place
,stretch
andpadding
have a default value, which are set in between the brackets ofdefault/.style={...}
which is used inside the first call of\pgfkeys
in the above MWE. There is also the comment 'change the default settings here'.EDIT2: The below code is everything inbetween of
\makeatletter
and\makeatother
and doesn't set 'table x.y' infront of the caption. Because of this, I also removed thelabel
-key as referencing won't work with this.\makeatother
EDIT3: Complete code (without
label
and without theTable x.y:
prefix) which includes two more options:font
are fontswitches applied to the table (stuff like\bfseries
,\footnotesize
or\small
)captionfont
are fontswitches applied to the captionBoth have the default to no change to surrounding fontswitches. If used both reset size and font and apply the argument provided.