LoginSignup
1
0

More than 3 years have passed since last update.

Texで画像がなぜか中央に来ないときの対処法

Posted at

普段から、wordばかり使っているせいか、いざTexで画像を挿入しようとしたらはまってしまった話。

出会ったトラブル

コメント 2020-08-09 225348.png
画像のように、なぜかキャプションが右寄りになっている。コードは次の通り。

main.tex
\documentclass[a4paper,titlepage]{jarticle}
\usepackage[dvipdfmx]{graphicx}

%(中略)

\begin{figure}[htbp]
    \begin{tabular}{cc}
        \begin{minipage}[t]{0.45\hsize}
            \centering
            \includegraphics[keepaspectratio, width=0.9\hsize, scale=1.0]{test_a.jpg}
            \caption{自然をイメージした画像}
            \label{fig:1}
        \end{minipage} 
        &
        \begin{minipage}[t]{0.45\hsize}
            \centering
            \includegraphics[keepaspectratio, width=0.9\hsize, scale=1.0]{test_b.jpg}
            \caption{都会をイメージした画像}
            \label{fig:2}
        \end{minipage}
    \end{tabular}
\end{figure}

%(後略)

調べたこと

  • \begin{tabular}{|c|c|}に変更した
  • \includegraphics全体を\fboxで囲ってみた

すると、画像のようになっていた。
コメント 2020-08-09 225239.png
見て分かる通り、\captionは正常にテーブルの中央付近に位置していた。一方で、画像が左下に寄っていた。......というよりは、画像の右側と上側に白い余白が勝手に挿入されていた。

原因はTexmarker

私は普段、Texの統合環境であるTexmarkerを利用している。Texmarkerをインストールしたのはかなり昔のことであったが、当時、「dvipdfm」の設定を書き換え忘れていた。初期設定ではdvipdfm %.dviとなっているが、ここをdvipdfmx %.dviと変更するだけで、すべて上手くいった。
image.png

自分が書いたコードに何か問題があるのだろうか、あるいは用意したJPEGファイルに問題があるのだろうか、といろいろ調べていて、Texmarker側の問題に気付くのが遅れてしまったところが反省点として挙げられる。

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0