The image included above is what I want to replicate - I want the name to appear on the top left, and the address/email-id to appear on the top right, and I want both of them to be aligned with the body of the文字.
以下是我的嘗試(等等文字是為了演示對齊問題)-
\documentclass[a4paper,10pt]{article}
\usepackage{a4wide}
\usepackage{color}
\usepackage{xcolor,mdframed}
\usepackage[hmargin=1cm,vmargin=1.5cm]{geometry}
\begin{document}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill} } l r }
\huge{\textbf{John Doe}} & Qtr D/40, Unit 12, Upper Kolkata\\
& (011) 2040-3455 [email protected]\\
\end{tabular*}
\bigskip
\begin{minipage}[c]{0.3\linewidth}
\begin{mdframed}[backgroundcolor=gray!10]
\bigskip
blah blah blah blah blah blah blah blah blah \
blah blah blah blah blah blah blah blah blah blah blah blah \
\bigskip
\end{mdframed}
\end{minipage}
\begin{minipage}[c]{0.2\linewidth}
\end{minipage}
\begin{minipage}[c]{0.6\linewidth}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah
\end{minipage}
\end{document}
我從中得到的是這樣的——
可以看出,右側的地址/電子郵件 ID 文字溢出並超出了文件其餘部分的文字邊距。
我如何解決它?另外,對於這種佈局使用表格是個好主意嗎?什麼是好的替代方案?
提前致謝。
答案1
我建議避免顯式標記,這既乏味又容易出錯。
我對標題的實作使用tabular*
兩個嵌套tabular
環境,確保與原始版本一樣垂直居中。
對於個人數據,我建議一個data
包含左側部分和右側部分的環境,每個部分都以相應的命令為前綴。在文件的開頭一次計算右側部分的寬度,並相應地計算左側部分的寬度,留下一些預定的空間(這裡是兩個em)。
\documentclass[a4paper,10pt]{article}
\usepackage[hmargin=1cm,vmargin=1.5cm,showframe]{geometry}
\usepackage{color}
\usepackage{xcolor,mdframed}
\newsavebox{\databox}
\newlength{\datawidth}
\AtBeginDocument{
\sbox{\databox}{%
\leftpart Mock text
\end{mdframed}\end{minipage}}
\setlength{\datawidth}{\wd\databox}
}
\newenvironment{data}
{\noindent\ignorespaces}
{\end{minipage}\par}
\newcommand{\leftpart}{%
\begin{minipage}{.3\textwidth}
\begin{mdframed}[
backgroundcolor=gray!10,
innertopmargin=\bigskipamount,
innerbottommargin=\bigskipamount]}
\newcommand{\rightpart}{%
\end{mdframed}
\end{minipage}\hfill
\begin{minipage}{\dimexpr\textwidth-2\tabcolsep-\datawidth}}
\begin{document}
\noindent%%% remember this
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill} } l r@{}}
\begin{tabular}{@{}l@{}}
\huge\bfseries John Doe
\end{tabular}
&
\begin{tabular}{@{}l@{}}
Qtr D/40, Unit 12, Upper Kolkata\\
(011) 2040-3455 [email protected]
\end{tabular}
\end{tabular*}
\bigskip
\begin{data}
\leftpart
blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah
\rightpart
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah
\end{data}
\end{document}
此showframe
選項當然僅適用於本範例。切勿使用過時的a4wide
軟體包。