LaTeX グラフィックス | \includegraphics コマンド
実際、LaTeX グラフィックスには言及すべき 2 つの側面があります:
- LaTeX/TeX コマンドを直接用いて記述されたベクターグラフィックス、
- EPS、PDF、またはラスター PNG や PDF などの外部フォーマットで記述された外部グラフィックスのインクルード。
前者はオリジナルの LaTeX とそのパッケージでのサポートが限定的です。TeX の垂直・水平ルールを利用して実装されています。これは、元の LaTeX が元の TeX エンジンに基づいており、主に DVI 形式で出力するため、線や曲線、あるいはバイナリのラスター画像データを表現するのに適さないからです。しかし、pdfTeX のようにグラフィックス対応形式(PDF など)への出力が可能なエンジンは、フォーマット依存のパッケージや機能を利用してグラフィックスを扱うことができます。同様の理由で、基本的な LaTeX では外部グラフィックスはサポートされていません。以下でグラフィックスのインクルード機能について説明します。
LaTeX graphics パッケージと \includegraphics コマンド
LaTeX のグラフィックスインクルードについて語るとき、最初に思い浮かぶのは \includegraphics コマンドです。これは graphics パッケージで定義されており、機能を有効にするためにプリアンブルでこのパッケージを呼び出す必要があります。
1\usepackage{graphics}使用している組版システムがデフォルトで pdfTeX などになっていない場合は、必要な driver ファイルを強制的に使用させるオプションを指定してください。
1\usepackage[pdftex]{graphics}driver ファイルは、パッケージコマンドとフォーマット依存の低レベル TeX 拡張プリミティブとのインターフェイスを実装するパッケージの一部です。Aspose.TeX の LaTeX グラフィックスサポートは独自のドライバを使用するように設定されているため、ドライバオプションを指定する必要はありません。
さて、PNG 画像を挿入する最もシンプルな方法は次のように記述することです。
1\includegraphics{sample-image.png}ここで sample-image.png は挿入したいファイル名です。拡張子を省略することも可能です。graphics パッケージはサポートされているフォーマットの定義リストを保持しており、ファイル検索時にそのリストを走査して最初に一致したファイルをインクルードします。
絶対パスや相対パスでファイル名を指定することもできます:
1\includegraphics{d:/sample-image.png} % absolute path
2\includegraphics{./sample-image.png} % relative to the current directory
3\includegraphics{../img/sample-image.png} % relative to the directory containing the current one別の方法として、\includegraphics を呼び出す前に \graphicspath コマンドで代替パスのリストを定義することができます:
1\graphicspath{{d:/img}{c:/img}{d:/work/img}}グラフィックスのスケーリング
LaTeX graphics パッケージはコンテンツを操作するコマンドを提供しています。そのため、以下のようにインクルードしたグラフィックス(実際には TeX/LaTeX コードで記述されたすべてのもの)を拡大縮小できます。
1\scalebox{.5}{\includegraphics{sample-image.png}} % scales both width and height by 0.5
2\scalebox{.5}[1.5]{\includegraphics{sample-image.png}} % scales the width and height by 0.5 and 1.5 respectivelyグラフィックのサイズ変更
拡大縮小と似ていますが、拡大率ではなく必要なサイズを指定します。
1\resizebox{10mm}{!}{\includegraphics{sample-image.png}} % changes the width to 10mm preserving the proprtions
2\resizebox{20mm}{10mm}{\includegraphics{sample-image.png}} % changes both width and height independentlyグラフィックの回転
1\rotatebox{25}{\includegraphics{sample-image.png}} % rotates the image by 25 degrees counterclockwiseLaTeX graphicx パッケージ
LaTeX graphicx パッケージは key=value インターフェイスを提供し、コンテンツ変換を簡単に行えるようにします。機能を有効にするには、プリアンブルでこのパッケージを呼び出してください。
1\usepackage{graphicx}
2\usepackage[pdftex]{graphicx} % with the driver option以下のオプションを任意に組み合わせることができますが、順序が重要であることに留意してください。
グラフィックビューポート
1\includegraphics[viewport=10 10 280 220]{sample-image.png} % sets the viewport with the lower left corner
2 % at the point (10, 10) (coinsides with (0, 0)
3 % of the box) and dimensions 280x220pt
4\includegraphics[viewport=10 10 250 220,clip]{sample-image.png} % the same, but the image is clipped by the viewportグラフィックのスケーリング
1\includegraphics[scale=.5]{sample-image.png} % scales both width and height by 0.5グラフィックのサイズ変更
1\includegraphics[width=15mm]{sample-image.png} % changes the width to 15mm preserving the proprtions
2\includegraphics[height=15mm,width=25mm]{sample-image.png} % changes both width and height independentlyグラフィックの回転
1\includegraphics[angle=10]{sample-image.png} % rotates the image by 10 degrees counterclockwisegraphics パッケージのバンドル機能の詳細については、ドキュメント
here と
here を参照してください。
Aspose.TeX for .NET API に基づいて構築された無料の変換 Web アプリ も確認することができます。