Saltar al contenido

Cómo alinear horizontalmente todos los caracteres como una máquina de escribir

Luego de mucho trabajar ya encontramos la contestación de esta incógnita que agunos usuarios de nuestro sitio web han presentado. Si deseas compartir algún detalle no dudes en aportar tu comentario.

Solución:

En respuesta al comentario de Nathanael, actualizo mi respuesta anterior con un método más poderoso, capaz de lidiar con material de varios párrafos, se permiten saltos de página.

Los saltos verticales adicionales entre párrafos (parskip) dentro del material especialmente centrado se perderá. Como esto suele ser 0pt además de un poco de pegamento estirable, este efecto no es muy significativo.

documentclass[a4paper]article
usepackage[paperheight=11cm,paperwidth=12cm,vscale=0.75,hscale=0.7]geometry
usepackagexcolor
usepackagelipsum

titleYour Paper
authorYou

% from Werner's answer

newcommandvmarkmboxrlapsmashcolorredrule[-3baselineskip].5pt4baselineskip

newcommandVmarkmboxrlapsmashcolorbluerule[-baselineskip].5pt3baselineskip

newlengthdimenA
newlengthdimenB

% command CenterIt
newcommandCenterIt[1]settowidthdimenB#1%
noindenthspacedimexpr((linewidth-dimenB)/2/dimenA)*dimenA #1par

% and now a *much* fancier tool, multi-paragraph-able, and allowing page breaks.

makeatletter
newboxtmpbox
newenvironmentttcentered%
  edef@tempa
     endgroup
      setbox[email protected]vboxsetboxtmpboxvbox%
                      noexpandcentering
                      begingroup
                      aftergroupnoexpand[email protected]
                      aftergroup%
                      aftergroupnoexpand[email protected]
                      defnoexpand @currenvir   @currenvir %
                      defnoexpand @currenvline [email protected] %
     @tempa% 

% remove or comment the Vmark for real use.
def[email protected]endgraf
  loop
        setbox[email protected]lastbox
        unskipunpenaltyunskipunpenalty
  ifvoid[email protected]else
        setbox[email protected]hboxstrut
Vmark 
                         unhbox[email protected]%
  setboxtmpbox
         vboxmoveright 
                dimexpr((linewidth-wd[email protected])/2/dimenA)*dimenArelax
                box[email protected]penalty[email protected]
                unvboxtmpbox%
 repeat
 globalsetbox@nevboxunvboxtmpbox

def[email protected]vspacedimexprbaselineskip-htstrutbox-prevdepth%
                   unvbox@ne
                   prevdepthdpstrutbox

makeatother

begindocument

ttfamily settowidthdimenAx

raggedright
CenterItvmark Top Secret Document
CenterItvmark This is a Top Secret Document
CenterItvmark This is a truly Top Secret Document

This is a top secret document containing secret information about a secret thing
which has remained secret for many years. This is a top secret document
containing secret information about a secret thing which has remained secret for
many years.

begincenter
  beginttcentered
    This is a top secret document containing secret information about a
    secret thing which has remained secret for many years. This is a top
    secret document containing secret information about a secret thing
    which has remained secret for many years.

    lipsum[1]
  endttcentered
endcenter

% debugging:
% showoutput

    We check the vertical spacing induced by the center environment and
    set up some centered text without extra vertical spacing (apart from
    the stringparskip=theparskip):

  beginttcentered
    This is a top secret document containing secret information about a 
    secret thing which has remained secret for many years. This is a top
    secret document containing secret information about a secret thing
    which has remained secret for many years.
  endttcentered


Back to normal raggedright (to confirm absence of extra vertical
spacing; apart from stringparskip=theparskip).

%showoutput
enddocument

alinear1

alinear2

alinear3


Primera respuesta:

Un método basado en medir las cosas primero. En cada línea. (vmark copiado de la respuesta de Werner)

documentclass[a4paper]article
usepackagexcolor% http://ctan.org/pkg/xcolor
newcommandvmarkmboxrlapsmashcolorredrule[-3baselineskip].5pt4baselineskip
usepackagecalc
titleYour Paper
authorYou

newlengthdimenA
newlengthdimenB

newcommandCenterIt[1]settowidthdimenB#1%
noindenthspacedimexpr((linewidth-dimenB)/2/dimenA)*dimenA #1par

begindocument
ttfamily 
settowidthdimenAx

raggedright



CenterItvmark Top Secret Document
CenterItvmark This is a Top Secret Document
CenterItvmark This is a truly Top Secret Document

This is a top secret document containing secret information about a secret thing which has remained secret for many years. This is a top secret document containing secret information about a secret thing which has remained secret for many years.
enddocument

alineación horizontal de la máquina de escribir

Una opción es utilizar un proceso de dos pasos:

  1. Utilizar el center entorno para identificar la ubicación del centro de texto con respecto a los otros elementos del documento.

  2. Utilizar una phantom para alinear horizontalmente y centrar manualmente el contenido.

ingrese la descripción de la imagen aquí

documentclassarticle
usepackagexcolor% http://ctan.org/pkg/xcolor
newcommandvmarkmboxrlapsmashcolorredrule[-3baselineskip].5pt4baselineskip
begindocument
ttfamilyraggedright

begincenter
vmark Top Secret Document
endcenter
This is a top secret document containing secret information 
about a secret thing which has remained secret for many years. 
This is a top secret document containing secret information 
about a secret thing which has remained secret for many years.

hrulefill

bigskip

leavevmodephantomThis is a top secret dovmark Top Secret Document

bigskip

This is a top secret document containing secret information 
about a secret thing which has remained secret for many years. 
This is a top secret document containing secret information 
about a secret thing which has remained secret for many years.

enddocument

Después de la primera center alineación, es obvio que una ubicación horizontal apropiada sería en algún lugar alrededor de la c de document.

Comentarios y puntuaciones de la guía

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *