
Me gustaría centrar (también alinear a la izquierda y alinear a la derecha) una parte de la oracióndentroun párrafo, que se puede hacer fácilmente en Word mediante [newline] + [center this line] + [newline]
. En LaTeX, sin embargo, el centering
comando afecta a todo el párrafo y, para afectar sólo a grupos, requiere un \par
al principio y al final de ese grupo. Mientras tanto, el center
entorno añade espacio vertical adicional. Sé que hay un centerline
comando que se adapta a mis necesidades, pero parece que no hay equivalentes en términos de "alinear a la izquierda" o "alinear a la derecha". Aquí está el MWE:
\documentclass{article}
\begin{document}
I want to center\\
"This piece of text"\\
within this paragraph.
I don't want to break the
{\par\centering paragraph like\par}
this.
How to achieve the effect\\
\centerline{without \texttt{centerline}}\\
or \begin{center}
the \texttt{center} environment?
\end{center}
\end{document}
Respuesta1
Nueva respuesta
Como lo señala@campaNo es necesario que definas tus propias contrapartes, ya que en realidad ya están contenidas en LaTeX y se llaman \leftline
y \rightline
. Entonces puedes usar
\documentclass[]{article}
\begin{document}
\hsize=5cm % just so that line breaks are a bit earlier
This is some longish text that is long and needs me to centre some
material\\
\centerline{here is center}
Also I'd like to display some stuff to the left\\
\leftline{here is left}
and to put something on the right\\
\rightline{here is right.}
\end{document}
Antigua respuesta
Conservado para la posteridad.
Puede obtener las contrapartes para la alineación izquierda y derecha definiéndolas. Lo siguiente debería ser suficiente. Tenga en cuenta que solo los contenidos que no sean más anchos que una sola línea funcionan según lo previsto, dentro de los cuales \@@line
no se producirá ningún salto de línea automático.
En caso de que te lo preguntes \hss
es un pegamento quehhorizontalmentestreguas osse reduce tanto como sea necesario para llenar el espacio especificado ( \@@line
es uno único \hbox
que debe ser tan ancho como el actual \hsize
, por lo que el ancho del texto).
\documentclass[]{article}
\makeatletter
\newcommand\leftalignline[1]{\@@line{#1\hss}}
\newcommand\rightalignline[1]{\@@line{\hss#1}}
\makeatother
\begin{document}
\hsize=5cm % just so that line breaks are a bit earlier
This is some longish text that is long and needs me to centre some
material\\
\centerline{here is center}
Also I'd like to display some stuff to the left\\
\leftalignline{here is left}
and to put something on the right\\
\rightalignline{here is right.}
\end{document}