%20todas%20las%20tablas%20de%20un%20documento.png)
Supongamos que quiero justificar a la izquierda todas mis tablas hasta una determinada línea vertical (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}
Esta solución funciona, pero quiero más flexibilidad. ¿Cómo, por ejemplo, voy a redefinir \leftpadding
para centrar todas las tablas a la vez? Debería ser posible, al menos en dos pasadas. La opción de justificar correctamente tampoco vendría mal. También se aceptan soluciones completamente diferentes para el mismo objetivo.
Respuesta1
Aunque no entiendo lo que quieres, aquí tienes una solución (que con suerte se adapta a tus necesidades) usando el pgfkeys
paquete -. Hice los subtítulos de manera que se puedan etiquetar (usando la label=
clave) pero no usan el \caption
comando internamente. Además, no usa su comando \leftpadding
sino la padding
tecla -.
\documentclass[11pt,a4paper,oneside]{memoir}
\pagestyle{plain}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%\usepackage{fontspec}
%\usepackage{changepage}
%\setmainfont[Mapping=tex-text]{Liberation Serif}
%\setsansfont[Mapping=tex-text]{Liberation Sans}
%\setmonofont[Mapping=tex-text]{Liberation Mono}
\usepackage{pgfkeys}
\makeatletter
\newif\if@placedleft
\newif\if@placedright
\newif\if@placedmiddle
\newif\if@placedcapused
\newif\if@placedscapused
\newif\if@placedlabused
\newdimen\@placedpadding
\newdimen\@placedrest
\pgfkeys{/placedt/.is family,/placedt,
default/.style={% change the default settings here
place=left,
stretch=1.4,
padding=1cm,
},
stretch/.estore in=\arraystretch,
place/.is choice,
place/left/.code=\@placedlefttrue\@placedrightfalse\@placedmiddlefalse,
place/right/.code=\@placedrighttrue\@placedleftfalse\@placedmiddlefalse,
place/middle/.code=\@placedmiddletrue\@placedleftfalse\@placedrightfalse,
padding/.estore in=\@placedpadding,
caption/.code=\@placedcapusedtrue\def\@placedcap{#1},
scaption/.code=\@placedscapusedtrue\def\@placedscap{#1},
label/.code=\@placedlabusedtrue\def\@placedlab{#1},
}
\newenvironment{placedtabular}[2][]{%
\par\medskip\noindent\begin{minipage}{\textwidth}%
\pgfkeys{/placedt, default, #1}%
\if@placedleft%
\@placedrest=\textwidth%
\advance\@placedrest by -\@placedpadding%
\hskip\@placedpadding%
\begin{minipage}{\@placedrest}%
\raggedright%
\else\if@placedmiddle%
\centering%
\else\if@placedright%
\@placedrest=\textwidth%
\advance\@placedrest by -\@placedpadding%
\begin{minipage}{\@placedrest}%
\raggedleft%
\fi\fi\fi%
\if@placedcapused%
\refstepcounter{table}%
\tablename~\thetable: \@placedcap%
\if@placedscapused%
\addcontentsline{lot}{table}{\@placedscap}%
\else%
\addcontentsline{lot}{table}{\@placedcap}%
\fi%
\if@placedlabused%
\label{\@placedlab}%
\fi%
\\[0.2\baselineskip]%
\fi%
\footnotesize\begin{tabular}{#2}%
}{
\end{tabular}%
\if@placedmiddle\else%
\end{minipage}%
\fi%
\end{minipage}%
}
\makeatother
\newcommand{\leftpadding}{1cm}
\begin{document}
\listoftables
\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.
\begin{placedtabular}[caption=Caption,label=tab:first]{|c|c|}
\hline
{Alfa}
& {Bravo}
\\\hline
{Charlie}
& {Delta}
\\\hline
\end{placedtabular}
\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.
\begin{placedtabular}[caption=Another Caption,label=tab:second]{|c|c|}
\hline
{Longer Echo}
& {Long Foxtrot}
\\\hline
{Golf}
& {Hotel}
\\\hline
\end{placedtabular}
\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}
EDITAR: Tenga en cuenta que he modificado ligeramente el código anterior.
El uso del placedtabular
entorno es normal tabular
, excepto que en el argumento opcional puede usar una key=value
sintaxis separada por comas. Las siguientes claves están disponibles:
stretch
: el valor utilizado paraarraystretch
place
: la ubicación de la mesa. Disponibles sonleft
,right
ymiddle
padding
: el espacio al margen izquierdo o derecho conplace=left
oplace=right
, respectivamentecaption
: el título utilizado para la tablascaption
: se utiliza el nombre de la tabla\listoftables
, si nocaption
se utiliza. Sicaption
no se utiliza, esto no tiene ningún efecto.label
: la etiqueta utilizada para hacer referencia a la tabla
Cuando utiliza una de estas claves en un placedtabular
entorno, los efectos son solo locales y no afectan a ninguna otra tabla configurada con este entorno.
De las claves antes mencionadas place
, stretch
y padding
tienen un valor predeterminado, que se establece entre corchetes y default/.style={...}
se usa dentro de la primera llamada de \pgfkeys
en el MWE anterior. También está el comentario "cambie la configuración predeterminada aquí".
EDITAR2: El siguiente código es todo lo que está entre \makeatletter
y \makeatother
y no establece la 'tabla xy' delante del título. Debido a esto, también eliminé la label
clave ya que las referencias no funcionarán con esto.
\makeatletter
\newif\if@placedleft
\newif\if@placedright
\newif\if@placedmiddle
\newif\if@placedcapused
\newif\if@placedscapused
%\newif\if@placedlabused
\newdimen\@placedpadding
\newdimen\@placedrest
\pgfkeys{/placedt/.is family,/placedt,
default/.style={%
place=left,
stretch=1.4,
padding=1cm,
},
stretch/.estore in=\arraystretch,
place/.is choice,
place/left/.code=\@placedlefttrue\@placedrightfalse\@placedmiddlefalse,
place/right/.code=\@placedrighttrue\@placedleftfalse\@placedmiddlefalse,
place/middle/.code=\@placedmiddletrue\@placedleftfalse\@placedrightfalse,
padding/.estore in=\@placedpadding,
caption/.code=\@placedcapusedtrue\def\@placedcap{#1},
scaption/.code=\@placedscapusedtrue\def\@placedscap{#1},
}
\newenvironment{placedtabular}[2][]{%
\par\medskip\noindent\begin{minipage}{\textwidth}%
\pgfkeys{/placedt, default, #1}%
\if@placedleft%
\@placedrest=\textwidth%
\advance\@placedrest by -\@placedpadding%
\hskip\@placedpadding%
\begin{minipage}{\@placedrest}%
\raggedright%
\else\if@placedmiddle%
\centering%
\else\if@placedright%
\@placedrest=\textwidth%
\advance\@placedrest by -\@placedpadding%
\begin{minipage}{\@placedrest}%
\raggedleft%
\fi\fi\fi%
\if@placedcapused%
\@placedcap%
\if@placedscapused%
\addcontentsline{lot}{table}{\@placedscap}%
\else%
\addcontentsline{lot}{table}{\@placedcap}%
\fi%
\\[0.2\baselineskip]%
\fi%
\footnotesize\begin{tabular}{#2}%
}{
\end{tabular}%
\if@placedmiddle\else%
\end{minipage}%
\fi%
\end{minipage}%
}
\makeatother
EDIT3: Código completo (sin label
y sin Table x.y:
prefijo) que incluye dos opciones más:
font
son interruptores de fuente aplicados a la tabla (cosas\bfseries
como\footnotesize
o\small
)captionfont
¿Se aplican cambios de fuente al título?
Ambos tienen el valor predeterminado de no realizar cambios en los interruptores de fuente circundantes. Si se usa, restablezca el tamaño y la fuente y aplique el argumento proporcionado.
\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}
\usepackage{pgfkeys}
\makeatletter
\newif\if@placedleft
\newif\if@placedright
\newif\if@placedmiddle
\newif\if@placedcapused
\newif\if@placedscapused
\newif\if@placedfontused
\newif\if@placedcfontused
\newdimen\@placedpadding
\newdimen\@placedrest
\pgfkeys{/placedt/.is family,/placedt,
default/.style={%
place=left,
stretch=1.4,
padding=1cm,
},
stretch/.estore in=\arraystretch,
place/.is choice,
place/left/.code=\@placedlefttrue\@placedrightfalse\@placedmiddlefalse,
place/right/.code=\@placedrighttrue\@placedleftfalse\@placedmiddlefalse,
place/middle/.code=\@placedmiddletrue\@placedleftfalse\@placedrightfalse,
padding/.estore in=\@placedpadding,
caption/.code=\@placedcapusedtrue\def\@placedcap{#1},
scaption/.code=\@placedscapusedtrue\def\@placedscap{#1},
font/.store in=\@placedfont,
captionfont/.store in=\@placedcapfont,
font/.code=\@placedfontusedtrue\def\@placedfont{#1},
captionfont/.code=\@placedcfontusedtrue\def\@placedcapfont{#1},
}
\newenvironment{placedtabular}[2][]{%
\par\medskip\noindent\begin{minipage}{\textwidth}%
\pgfkeys{/placedt, default, #1}%
\if@placedleft%
\@placedrest=\textwidth%
\advance\@placedrest by -\@placedpadding%
\hskip\@placedpadding%
\begin{minipage}{\@placedrest}%
\raggedright%
\else\if@placedmiddle%
\centering%
\else\if@placedright%
\@placedrest=\textwidth%
\advance\@placedrest by -\@placedpadding%
\begin{minipage}{\@placedrest}%
\raggedleft%
\fi\fi\fi%
\if@placedcapused%
{\if@placedcfontused\normalsize\normalfont\@placedcapfont\fi\@placedcap}%
\if@placedscapused%
\addcontentsline{lot}{table}{\@placedscap}%
\else%
\addcontentsline{lot}{table}{\@placedcap}%
\fi%
\\[0.2\baselineskip]%
\fi%
\if@placedfontused\normalsize\normalfont\@placedfont\fi%
\begin{tabular}{#2}%
}{
\end{tabular}%
\if@placedmiddle\else%
\end{minipage}%
\fi%
\end{minipage}%
}
\makeatother
\newcommand{\leftpadding}{1cm}
\begin{document}
\listoftables
\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.
\begin{placedtabular}[caption=Caption,font=\bfseries]{|c|c|}
\hline
{Alfa}
& {Bravo}
\\\hline
{Charlie}
& {Delta}
\\\hline
\end{placedtabular}
\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.
\begin{placedtabular}[caption={Another\protect\\Caption}]{|c|c|}
\hline
{Longer Echo}
& {Long Foxtrot}
\\\hline
{Golf}
& {Hotel}
\\\hline
\end{placedtabular}
\begin{placedtabular}[caption=Another Caption]{|c|c|}
\hline
{Longer Echo}
& {Long Foxtrot}
\\\hline
{Golf}
& {Hotel}
\\\hline
\end{placedtabular}
\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}