Pregunta

¿Cómo centrar el texto dentro de una lista de látex?

O de otra manera no usar lista. (Necesidad de una caja con fuente de espacio sencillo)

¿Fue útil?

Solución

la respuesta dada en tex.stackexchange es:

\documentclass{article}
\usepackage{listings}
\renewcommand{\figurename}{Listing}
                    % replace figurename with the text that should preceed the caption
\begin{document}

\begin{figure}[thp] % the figure provides the caption
\centering          % which should be centered
\caption{Ausgabe des C-Programms}
\begin{tabular}{c}  % the tabular makes the listing as small as possible and centers it
\begin{lstlisting}[label={gtt_c_ausgabe}]
printf("Your code goes here.\n");
\end{lstlisting}
\end{tabular}
\end{figure}

\end{document}

... y aún me queda preguntándose:

Uso de un marco alrededor del código, por ejemplo, utilizando \lstset{frame=single,frameround=tttt}, coloca a la forma del marco hacia la derecha. ¿Cómo se puede evitar esto?

¿Qué hace el bit renewcommand?

Otros consejos

No tengo una respuesta para el paquete de lista en la parte superior de mi cabeza, pero se puede intentar lo siguiente:

\framebox[.9\linewidth]{\parbox{.85\linewidth}{\tt Hello World\\Second line}}

que produce una caja con 90% de la anchura de la línea, con el texto de la anchura de 85% del ancho de línea.

Si usted quiere que centra simplemente hay que poner \centering delante del comando \tt:

\framebox[.9\linewidth]{\parbox{.85\linewidth}{\centering \tt Hello World\\Second line}}

Si prefiere el cuadro sin marco, basta con cambiar \framebox en \makebox (y mantener los argumentos en su forma actual).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top