سؤال

كيف يمكنني مركز النص داخل قائمة في LaTex؟

أو طريقة أخرى لا تستخدم القائمة. (بحاجة إلى صندوق بخط Monospace)

هل كانت مفيدة؟

المحلول

الجواب المعطى في Tex.StackexChange هو:

\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}

... الذي لا يزال يتركني أتساءل:

باستخدام إطار حول الكود ، على سبيل المثال باستخدام \lstset{frame=single,frameround=tttt}, ، يضع الإطار الطريق إلى اليمين. كيف يمكن تجنب هذا؟

ماذا يكون ال renewcommand قليلا تفعل؟

نصائح أخرى

ليس لدي إجابة لحزمة الإدراج أعلى رأسي ، ولكن يمكنك تجربة ما يلي:

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

ينتج ذلك صندوقًا مع 90 ٪ من عرض الخط ، مع نص عرض 85 ٪ من عرض الخط.

إذا كنت تريد أن تركز عليك فقط وضعك \centering أمام ال \tt يأمر:

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

إذا كنت تفضل المربع بدون إطار ، فما عليك سوى التغيير \framebox داخل \makebox (والحفاظ على الحجج كما يقفون).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top