2010-06-24 10 views
20

이것은 나를 미치게합니다.센터 라텍스 lstlisting

저는 LaTeX에서 lstlisting을 중심으로하고 싶습니다. 그 오른쪽으로 이동,

\lstset{ % 
    caption=Descriptive Caption Text, 
    label=lst:descr_capti_text, 
    basicstyle=\ttfamily\footnotesize\bfseries, 
    frame=tb, 
    linewidth=0.6\textwidth 
} 
\centering\begin{tabular}{c} 
\begin{lstlisting} 
printf("this should be centered!"); 
\end{lstlisting} 
\end{tabular} 

이것은 캡션을 중심에 lstlisting을 가하고 것이 아니라 : 여기에 시도

3 후 시간이 몇 가지 코드입니다. 표를 꺼내면 캡션이 가운데에 오게되지만 코드는 왼쪽으로갑니다! :(

감사합니다.

+4

그냥 내가 [LaTeX의 StackExchange 제안]을 말할 줄 알았는데 (http://area51.stackexchange.com/proposals/2148/tex-latex-and- : 다음 코드는 센터 나의 미니 환경없이 작동 friends? referrer = 5z6F4dAmVScN5QfMOt5KEg2) 일단 이륙하면이 같은 질문에 가장 적합 할 것입니다. –

답변

7

자막이 실제로 당신은 그냥 맨과는 0.6\textwidth 긴 목록의 하단에 실행 라인을 만들고있다. 목록 위에 중심이다.이는 자막처럼 보이게 중심을 벗어난했다 (위 아래 라인을 단축하지 않으면 볼 수 있음) 또한, 당신의 \centering 목록을 중심으로하지 않습니다

이 작동합니다 :..

\begin{center} 
    \lstset{% 
    caption=Descriptive Caption Text, 
    basicstyle=\ttfamily\footnotesize\bfseries, 
    frame=tb 
    } 
    \begin{lstlisting} 
    printf("this should be centered!"); 
    \end{lstlisting} 
\end{center} 

당신은 설명하지 않는다 왜 당신이 구분을 원하니? 라인 수는 0.6\textwidth입니다. 실제로 목록의 너비를 해당 값으로 설정하려면 접근 방식으로 원하는대로 할 수 없습니다. minipage와 같은 것을 사용하여 전체 목록에 대해 너비를 설정하십시오 ( ).

begin{minipage}{0.6\textwidth} 
    \begin{center} 
    \lstset{% 
     caption=Descriptive Caption Text, 
     basicstyle=\ttfamily\footnotesize\bfseries, 
     frame=tb, 
    } 
    \begin{lstlisting} 
     printf("this should be centered!"); 
    \end{lstlisting} 
    \end{center} 
\end{minipage} 
+0

Akim과 마찬가지로, 나는 센터 환경 내에서 minipage와 함께 작동한다는 것을 알았습니다. – luketorjussen

+1

불행히도 이것은 나를 위해 작동하지 않습니다. 목록은 이동하지 않습니다. – kaoD

+3

'\ begin {center}'를 사용하면 목록을 센터링하는 데 아무런 영향을 미치지 않습니다. –

4

실제로 나를 위해 일한 것은 반대로 센터 환경 안에 미니 페이지를 넣는 것입니다. 대신 (참조 texdoc listings 장 4.10) xrightmargin 및 xleftmargin 를 사용하는 것이 좋습니다 당신 선폭 사용

+0

나를 위해서도 똑같이. – Cemre

19

.

\lstset{ 
    caption=Descriptive Caption Text, 
    basicstyle=\footnotesize, frame=tb, 
    xleftmargin=.2\textwidth, xrightmargin=.2\textwidth 
} 
\begin{lstlisting} 
    printf("this should be centered!"); 
\end{lstlisting} 
+0

놀랍다, 이것은 내가 찾고있는 것이었다. 내 경우에는'xrightmargin'에 음의 값을 사용했기 때문에 lslisting 프레임을 주위로 옮길 수 있습니다. 힌트를 보내 주셔서 감사합니다! – guipy