我想将两张图片并排放置,我已经看到了LaTeX 图形并排显示但其中一个答案给了我Environment subfigure undefined
错误,我一点也不知道为什么。这个想法是将两个子图并排放置在一个主图中。
这是我的代码:
\documentclass [10pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[portuguese]{babel}
\usepackage[T1]{fontenc}
\usepackage{hyphenat}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{geometry}
\usepackage{subfig}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}{0.5\textwidth}
\centering
\includegraphics[width=0.4\textwidth]{impedância Ri1.png}
\caption{*caption*}
\label{fig:sub1}
\end{subfigure} %
\begin{subfigure}{0.5\textwidth}
\centering
\includegraphics[width=0.4\textwidth]{impedância ri2.png}
\caption{*caption*}
\label{fig:sub2}
\end{subfigure}
\caption{*caption*}
\end{figure}
\end{document}
有什么帮助吗?
答案1
您将两种不同的方法混合在一起。您不能同时使用它们。我同时使用这两种方法来实现相同的结果:
\usepackage{subcaption}
\documentclass [10pt, a4paper]{article}
\usepackage[hidelinks]{hyperref}
\usepackage[utf8]{inputenc}
\usepackage[portuguese]{babel}
\usepackage[T1]{fontenc}
\usepackage{hyphenat}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{geometry}
\usepackage{subcaption}
\begin{document}
Left is \ref{fig:sub1}. Right is \ref{fig:sub2}
\begin{figure}
\centering
\begin{subfigure}{0.4\textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{*caption*}
\label{fig:sub1}
\end{subfigure}\hskip1ex
\begin{subfigure}{0.4\textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{*caption*}
\label{fig:sub2}
\end{subfigure}
\caption{*caption*}
\end{figure}
\end{document}
\usepackage{subfig}
\documentclass [10pt, a4paper]{article}
\usepackage[hidelinks]{hyperref}
\usepackage[utf8]{inputenc}
\usepackage[portuguese]{babel}
\usepackage[T1]{fontenc}
\usepackage{hyphenat}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{geometry}
\usepackage{subfig}
\begin{document}
Left is \ref{fig:sub1}. Right is \ref{fig:sub2}.
\begin{figure}
\centering
\subfloat[*caption*]{\includegraphics[width=0.4\textwidth]{example-image}\label{fig:sub1}}\hskip1ex
\subfloat[*caption*]{\includegraphics[width=0.4\textwidth]{example-image}\label{fig:sub2}}
\caption{*caption*}
\end{figure}
\end{document}
输出: