5

このSO Q & Aが示すように、\textwidth がわかりにくいことがわかりました。

通常の場合はテキストの幅ですが、この変数は複数列のテキストの幅に関する正しい情報を持っていないようです。

これは、\textwidth の幅を出力する LaTeX コードです (ここからコードをコピーしました)。

\documentclass[]{記事}
\usepackage{レイアウト}
\usepackage{multicol}

\usepackage[左=20mm、右=20mm、上=33.95mm、下=33.95mm]{形状}

\begin{ドキュメント}
cm 単位のテキスト幅: \printinunitsof{cm}\prntlen{\textwidth}

\begin{multicols}{2}
cm 単位のテキスト幅: \printinunitsof{cm}\prntlen{\textwidth}
\end{複数列}

\end{ドキュメント}

その結果、複数列の場合、\textwidth を使用してテキストをボックス化することはできません。

\begin{tikzpicture}
  \draw node[draw=black,fill=black!20,rounded corners,inner sep=2ex,text width=\textwidth] {
    Lorem ipsum dolor sit amet \dots
    };
\end{tikzpicture}

また

\colorbox{red}{\parbox{\textwidth}{赤い背景に黒いテキスト}}
  • 複数列ドキュメントの実際の \texwidth を知る方法は?
  • \linewidth の何が問題になっていますか? 次の例を試しましたが、示されているように結果は正しくありません。\listing 環境で正しい結果が得られます。
\documentclass[]{記事}
\usepackage{レイアウト}
\usepackage{multicol}
\usepackage{tikz}
\usepackage{色}
\usepackage{リスト}

\usepackage[左=20mm、右=20mm、上=33.95mm、下=33.95mm]{形状}

\begin{ドキュメント}
cm 単位のテキスト幅: \printinunitsof{cm}\prntlen{\textwidth}
cm 単位のテキスト幅: \printinunitsof{cm}\prntlen{\linewidth}

\colorbox{darkgrey}{赤地に黒文字}

\noindent\colorbox{darkgrey}{\parbox{\linewidth}{赤い背景に黒いテキスト}}

\begin{multicols}{2}


こいつは深い。etaoin shrdlu を覚えていますか? (気にしないかもしれません。気にしないでください。この件に関する速報が近日中に公開されます。) イルミナティと fnord を覚えていますか?Lorem ipsum も同じです。確かにそれは何かを意味します。確かに、ミストパワーが投資されています。Lorem ipsum、私の子供たち。だからモテる。

cm 単位のテキスト幅: \printinunitsof{cm}\prntlen{\textwidth}
cm 単位のテキスト幅: \printinunitsof{cm}\prntlen{\linewidth}

こいつは深い。etaoin shrdlu を覚えていますか? (気にしないかもしれません。気にしないでください。この件に関する速報が近日中に公開されます。) イルミナティと fnord を覚えていますか?Lorem ipsum も同じです。確かにそれは何かを意味します。確かに、ミストパワーが投資されています。Lorem ipsum、私の子供たち。だからモテる。


\noindent\colorbox{darkgrey}{赤い背景に黒いテキスト}

\noindent\colorbox{darkgrey}{\parbox{\linewidth}{赤い背景に黒いテキスト}}

\noindent\begin{tikzpicture}
  \draw node[draw=black,fill=black!20,rounded corners,inner sep=2ex,text width=\linewidth] {
    Lorem ipsum dolor sit amet \dots
    };
\end{tikzpicture}

\definecolor{ダークグレー}{rgb}{0.95,0.95,0.95}
\lstset{backgroundcolor=\color{ダークグレー}}
\lstset{columns=fullflexible, basicstyle=\ttfamily, basicstyle=\tiny, numbers=left, numberstyle=\tiny, stepnumber=2, numbersep=5pt}
\begin{lstlisting}[frame=tb]
(let ((buffer (url-retrieve-synchronously
           "http://tromey.com/elpa/package-install.el")))
  (保存エクスカーション
    (セットバッファバッファ)
    (goto-char (ポイント分))
    (re-search-forward "^$" nil 'move) ;;$
    (評価領域 (ポイント) (ポイント-masx))
    (kill-buffer (current-buffer))))
\end{lstlisting}

\end{複数列}

\end{ドキュメント}

http://img571.imageshack.us/img571/1867/screenshot20100718at407.png

4

1 に答える 1

2

以下のコードを見てください。これにより、ボックスが列テキストの右マージンと同じ高さになります。multicol 環境の \linewidth はテキストの幅ではないようです。代わりに、列テキストの幅は \linewidth - (\columnsep / #ofCols) として計算されます (と思います)。また、tikz の画像では、内側のセパレーションがボックスの幅に追加されるため、ボックスの幅を設定するときにそれを差し引く必要があります。少なくとも私にはそう思われます:

\documentclass[]{article}
\usepackage{layouts}
\usepackage{multicol}
\usepackage{tikz}
\usepackage{color}
\usepackage{listings}

\usepackage[left=20mm,right=20mm,top=33.95mm,bottom=33.95mm]{geometry}

\begin{document}
textwidth in cm: \printinunitsof{cm}\prntlen{\textwidth}
textwidth in cm: \printinunitsof{cm}\prntlen{\linewidth}

\colorbox{darkgray}{Black text on red background}

\noindent\colorbox{darkgray}{\makebox[\linewidth]{Black text on red background}}

\begin{multicols}{2}


This one is deep. Remember etaoin shrdlu? (Maybe you don't. Never mind, a bulletin on the subject is forthcoming.) Remember the Illuminati and fnord? Lorem ipsum is the same deal--one of those inscrutable phrases that just keeps turning up. Surely it means something. Surely it's invested with, you know, mysto power. Lorem ipsum, my children. So mote it be.

textwidth in cm: \printinunitsof{cm}\prntlen{\textwidth}
textwidth in cm: \printinunitsof{cm}\prntlen{\linewidth}
\newlength{\mywidth}
\setlength{\mywidth}{\linewidth}
\addtolength{\mywidth}{-0.5\columnsep}
\newlength{\mytikzwidth}
\setlength{\mytikzwidth}{\linewidth}
\addtolength{\mytikzwidth}{-4ex}
mywidth: \the\mywidth\\ columnsep: \the\columnsep\\
\noindent\colorbox{lightgray}{\makebox[\mywidth][c]{Black text on red background}}

This one is deep. Remember etaoin shrdlu? (Maybe you don't. Never mind, a bulletin on the subject is forthcoming.) Remember the Illuminati and fnord? Lorem ipsum is the same deal--one of those inscrutable phrases that just keeps turning up. Surely it means something. Surely it's invested with, you know, mysto power. Lorem ipsum, my children. So mote it be.


\noindent\colorbox{darkgray}{Black text on red background}
mywidth: \the\mywidth columnsep: \the\columnsep colwidth: \the\columnwidth \\

\noindent\colorbox{lightgray}{\makebox[\mywidth][c]{Black text on red background}}

\noindent\begin{tikzpicture}
  \draw node[draw=black,fill=black!20,rounded corners,inner sep=2ex,text width=\mytikzwidth] {
    Lorem ipsum dolor sit amet \dots
    };
\end{tikzpicture}

\definecolor{darkgray}{rgb}{0.95,0.95,0.95}
\lstset{backgroundcolor=\color{darkgray}}
\lstset{columns=fullflexible, basicstyle=\ttfamily,  basicstyle=\tiny, numbers=left, numberstyle=\tiny, stepnumber=2, numbersep=15pt}
\begin{lstlisting}%[frame=tb]
(let ((buffer (url-retrieve-synchronously
           "http://tromey.com/elpa/package-install.el")))
  (save-excursion
    (set-buffer buffer)
    (goto-char (point-min))
    (re-search-forward "^$" nil 'move)  ;;$
    (eval-region (point) (point-masx))
    (kill-buffer (current-buffer))))
\end{lstlisting}

\end{multicols}

\end{document}
于 2010-07-19T02:33:28.063 に答える