我想请教一下如何强制将 tikzpicture 置于多列顶部。结果如下。
\documentclass[11pt,english,singlespacing]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{multicol}
\usepackage{listings}
\usepackage{tikz}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{geometry}
\lstset{
basicstyle=\footnotesize
}
\geometry{
paper=a4paper,
inner=1in,
outer=1in,
top=.6in,
bottom=.8in
}
\begin{document}
\section{Introduction}
\paragraph*{Nice paragraph}
\begin{multicols}{2}
\begin{small}
\begin{itemize}
\item[]
\begin{minipage}{\linewidth}
\begin{tikzpicture}
\draw (0,0) -- (4,0) -- (4,3) -- cycle;
\end{tikzpicture}
\begin{lstlisting}
\begin{tikzpicture}
\draw (0,0) -- (4,0) -- (4,3) -- cycle;
\end{tikzpicture}
\end{lstlisting}
\end{minipage}
\columnbreak
\item[]
\begin{minipage}{\linewidth}
\setlength{\unitlength}{1cm}
\begin{picture}(7,5)(0,0)
\put(0,0){\line(1,0){4}}
\put(4,0){\line(0,1){3}}
\put(0,0){\line(4,3){4}}
\end{picture}
\begin{lstlisting}
\begin{picture}(7,5)(0,0)
\put(0,0){\line(1,0){4}}
\put(4,0){\line(0,1){3}}
\put(0,0){\line(4,3){4}}
\end{picture}
\end{lstlisting}
\end{minipage}
\end{itemize}
\end{small}
\end{multicols}
\end{document}
有什么办法可以强制这个位置吗?
答案1
基本上,您需要做的就是使用\makebox
、\parbox
或指定宽度,minipage
并用\hfill
. 将它们分开(Tabularx
也是一个选项)。图片通常按底部对齐,但您可以使用\raisebox{-\height}{...}
来对齐其顶部。
\documentclass[11pt,english,singlespacing]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{multicol}
\usepackage{listings}
\usepackage{tikz}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{geometry}
\lstset{
basicstyle=\footnotesize
}
\geometry{
paper=a4paper,
inner=1in,
outer=1in,
top=.6in,
bottom=.8in
}
\begin{document}
\section{Introduction}
Nice paragraph
\begin{small}
\noindent\makebox[0.45\textwidth][l]{%
\begin{tikzpicture}
\draw (0,0) -- (4,0) -- (4,3) -- cycle;
\end{tikzpicture}}%
\hfill\makebox[0.45\textwidth][l]{%
\setlength{\unitlength}{1cm}
\begin{picture}(3,2)(0,0)
\put(0,0){\line(1,0){4}}
\put(4,0){\line(0,1){3}}
\put(0,0){\line(4,3){4}}
\end{picture}}
\noindent\begin{minipage}[t]{0.45\textwidth}
\begin{lstlisting}
\begin{tikzpicture}
\draw (0,0) -- (4,0) -- (4,3) -- cycle;
\end{tikzpicture}
\end{lstlisting}
\end{minipage}\hfill\begin{minipage}[t]{0.45\textwidth}
\begin{lstlisting}
\begin{picture}(3,2)(0,0)
\put(0,0){\line(1,0){4}}
\put(4,0){\line(0,1){3}}
\put(0,0){\line(4,3){4}}
\end{picture}
\end{lstlisting}
\end{minipage}
\end{small}
\end{document}