在此代码中
\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage[ngerman]{babel}
\usepackage{siunitx}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{graphicx}
\usepackage{lastpage}
\usepackage{xltabular,array}
\usepackage{showframe}
\sisetup{per-mode=fraction}
\pagestyle{empty}
\begin{document}
\vspace*{-2cm}
\noindent % it doesn't seem to make a difference
\begin{tabular}{|>{\raggedright\arraybackslash}m{3cm}|>{\raggedright\arraybackslash}m{7cm}|>{\raggedright\arraybackslash}m{5cm}|>{\raggedright\arraybackslash}m{2cm}|}
\hline
%\rule[-1ex]{0pt}{0.5ex}
\includegraphics[width=3cm]{example-image} &
\multicolumn{2}{|>{\raggedright\arraybackslash}m{12cm}|}{\rule[-1ex]{0pt}{4.5ex}{\LARGE \textbf{Mein-wunderschönes-Gymnasium}}} & \\
&
\multicolumn{2}{|>{\raggedright\arraybackslash}m{12cm}|}{{\rule[-2ex]{0pt}{6.5ex} \textbf{\Large Aufbau eines Versuchsprotokolls}}} &
\rule[-2ex]{0pt}{6.5ex} {\Large \textbf{(WHO)}} \\
\rule[-1ex]{0pt}{7.5ex} {\Large Klasse:} &
\rule[-1ex]{0pt}{7.5ex} {\Large Name:} &
\rule[-1ex]{0pt}{7.5ex} {\Large Datum:} &
\rule[-1ex]{0pt}{7.5ex} {\Large Seite \thepage\ von \pageref{LastPage}} \\
\hline
\end{tabular}
\section*{Section title begins here}
Text begins here.
\end{document}
我得到的表格不是从文本边缘左侧开始对齐的。我添加了框架来显示我的意思。我得到了
我知道我可以用 将桌子拉到左边\hspace
,但这需要反复试验。我需要调整长度来自动修复这个问题吗?(不用担心桌子也太宽了:我会在正确对齐后立即修复这个问题)。
答案1
您需要桌子吗?
\documentclass[11pt]{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{graphicx}
\usepackage{lastpage}
%\usepackage{showframe}
\pagestyle{empty}
\begin{document}
\vspace*{-2cm}
\noindent\begin{minipage}{\textwidth}
\hrule\smallskip
\LARGE
\makebox[0pt][l]{%
\begin{tabular}{@{}c@{}}\includegraphics[width=3cm]{example-image}\end{tabular}%
}\hfill
\textbf{Mein-wunderschönes-Gymnasium}\hspace*{\fill}
\Large
\hspace*{\fill}\textbf{Aufbau eines Versuchsprotokolls\hspace*{\fill}\makebox[0pt][r]{(WHO)}}
\bigskip
\makebox[0.2\textwidth][l]{Klasse:}%
\makebox[0.4\textwidth][l]{Name:}%
\makebox[0.2\textwidth][l]{Datum:}\hfill
\begin{tabular}{@{}l@{}}Seite \thepage\ \\ von \pageref{LastPage}\end{tabular}
\smallskip
\hrule
\end{minipage}
\section*{Section title begins here}
Text begins here.
\end{document}
没有showframe
您甚至可以让标题大于文本宽度:
\documentclass[11pt]{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{graphicx}
\usepackage{lastpage}
%\usepackage{showframe}
\pagestyle{empty}
\begin{document}
\vspace*{-2cm}
\noindent\hspace{-1cm}\begin{minipage}{\dimexpr\textwidth+2cm}
\hrule\smallskip
\LARGE
\makebox[0pt][l]{%
\begin{tabular}{@{}c@{}}\includegraphics[width=3cm]{example-image}\end{tabular}%
}\hfill
\textbf{Mein-wunderschönes-Gymnasium}\hspace*{\fill}
\Large
\hspace*{\fill}\textbf{Aufbau eines Versuchsprotokolls\hspace*{\fill}\makebox[0pt][r]{(WHO)}}
\bigskip
\makebox[0.2\textwidth][l]{Klasse:}%
\makebox[0.4\textwidth][l]{Name:}%
\makebox[0.2\textwidth][l]{Datum:}\hfill
\begin{tabular}{@{}l@{}}Seite \thepage\ \\ von \pageref{LastPage}\end{tabular}
\smallskip
\hrule
\end{minipage}\hspace*{-1cm}
\section*{Section title begins here}
Text begins here.
\end{document}
答案2
除了消除后面的空行之外\noindent
,您可能还想(a)确保表格实际上适合文本块以及(b)整理代码,可能如下所示。
\documentclass[11pt]{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{amsmath}
\usepackage[ngerman]{babel}
\usepackage{siunitx}
\usepackage{graphicx,lastpage,xltabular,array,calc}
\newcolumntype{M}[1]{>{\raggedright\arraybackslash}m{#1}}
%\usepackage{showframe}
\sisetup{per-mode=fraction}
\pagestyle{empty}
\begin{document}
\noindent % it makes a huge difference...
\begin{tabular}{@{}
M{3cm}
M{7cm-2\tabcolsep}
M{4.75cm-2\tabcolsep}
M{2.25cm-2\tabcolsep} @{}}
\hline
%\rule[-1ex]{0pt}{0.5ex}
\includegraphics[width=3cm-\tabcolsep]{example-image} &
\multicolumn{2}{c}{\LARGE\textbf{Mein wunderschönes Gymnasium}} & \\
&
\multicolumn{2}{c}{\rule[-2ex]{0pt}{6.5ex}\Large\textbf{Aufbau eines Versuchsprotokolls}} &
\Large \textbf{(WHO)} \\
\rule[-1ex]{0pt}{7.5ex}\Large Klasse: &
\rule[-1ex]{0pt}{7.5ex}\Large Name: &
\rule[-1ex]{0pt}{7.5ex}\Large Datum: &
\rule[-1ex]{0pt}{7.5ex}\Large Seite \thepage\ von \pageref{LastPage} \\
\hline
\end{tabular}
\section*{Section title begins here}
Text begins here.
\end{document}