我将非常感激能得到关于以下问题的帮助:我希望得到以下结果:
灰色框完全位于边距之外,但文档中的图像和其余文本具有特定边距。我还想在彩色框中包含文本列表。
我能得到的最接近的答案是:
\noindent
\fcolorbox{MyGray2}{MyGray2}{\parbox{\paperwidth-3.0\fboxsep-3.0\fboxrule}{\includegraphics[scale=0.1, left=5in]{cvbild.jpg}}{Hejhejhejhejhejhej akj kajhf kjhj hkdjfh skdjfh ksdjfg kdsg }}
但是左边的边缘仍然是白色的,并且文本甚至没有接近我想要的位置。
另一个尝试是制作\mybox
并更改框上方的边距,但随后我在框前后得到了一个新页面。
\newtcolorbox{mybox}{
arc=0pt,
boxrule=0pt,
colback=MyGray2,
% width=0.2\textwidth, % this option controls the width of the box
colupper=black,
fontupper=\bfseries
}
\begin{document}
\newgeometry{left=0in,right=0in} % set new margins
\nopagebreak[4] % doesn't work
\begin{mybox}
\includegraphics[scale=.1, left]{cvbild.jpg}{example varfö alajlkejf ksdf }
\end{mybox}
\restoregeometry % restore margins
答案1
可以使用tcolorbox
或者mdframed
,但是这也可以不使用那些功能强大的包,而是使用一些盒子(例如,一个\makebox
,一个\parbox
宽度等于\paperwidth
,一个\colorbox
和一些minipage
s 作为内部内容)来实现;类似这样的:
\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{lipsum}% just to generate filler text
\begin{document}
\lipsum[4]
\par\medskip
\noindent\makebox[\linewidth][c]{%
\colorbox{gray!30}{%
\parbox{\paperwidth}{%
\hspace*{\dimexpr\hoffset+\oddsidemargin+1in\relax}%
\begin{minipage}{.2\textwidth}
\includegraphics[width=\linewidth,height=3cm]{example-image-a}
\end{minipage}%
\begin{minipage}{.05\textwidth}
\mbox{}
\end{minipage}%
\begin{minipage}{.75\textwidth}
Some other text\par\bigskip
\begin{tabular}{@{}ll@{}}
Email \\
Phone \\
Address
\end{tabular}
\end{minipage}%
}%
}%
}\par\medskip
\lipsum[4]
\end{document}
结果:
答案2
我的答案是使用tcolorbox
。\mybox
构造一个宏,以图片文件名和文本内容为参数。此外,tcolorbox
还可以提供选项。
我注释了以下源代码以帮助您调整应用程序的设置:
\documentclass{article}
\usepackage{lipsum}
\usepackage[skins,xparse]{tcolorbox}
\NewTotalTColorBox{\mybox}{ O{} m +m }{%
enhanced,sidebyside,size=tight,boxrule=0pt,frame hidden,
lower separated=false,fontlower=\sffamily,
extrude left by=\dimexpr\hoffset+\oddsidemargin+1in\relax,
extrude right by=\dimexpr\paperwidth-\textwidth-\hoffset-\oddsidemargin-1in\relax,
colback=gray!30,% <-- color
lefthand width=0.2\textwidth,% <-- width of picture
sidebyside gap=1cm,% <-- distance between picture and text
before skip=8pt,% <-- space before
after skip=8pt,% <-- space after
#1
}{\includegraphics[width=\linewidth]{#2}\tcblower #3}
\begin{document}
\lipsum[2]
\mybox{photo.png}
{
Listet text here\par\bigskip
\begin{tabular}{@{}ll@{}}
Email & [email protected]\\
Phone & 555 666\\
Address & Green Lane, Hometown
\end{tabular}
}
\lipsum[3]
% Example: optionally adapt picture width
\mybox[lefthand width=0.3\textwidth]
{example-image-a.png}
{
Listet text here\par\bigskip
\begin{tabular}{@{}ll@{}}
Email & [email protected]\\
Phone & 555 666\\
Address & Green Lane, Hometown
\end{tabular}
}
\lipsum[4]
\end{document}
结果是:
答案3
这里我只使用了一个堆栈。
\documentclass[12pt]{article}
\usepackage[usestackEOL]{stackengine}
\def\stacktype{L}\def\stackalignment{l}
\usepackage{xcolor,graphicx, lipsum}
\begin{document}
\sffamily
\lipsum[1]
\noindent\addstackgap{\stackon[0pt]{%
\makebox[\textwidth]{\textcolor{blue!10}{\rule{1.01\paperwidth}{6\baselineskip}}}%
}{%
\includegraphics[width=1.1in,height=6\baselineskip]{example-image-a}%
\hspace{.5in}%
\raisebox{.7\baselineskip}{\Longstack{Listed text here\\ \\Email\\Phone\\Address}}%
}}
\noindent Margins here for the rest of the text
\end{document}
答案4
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\node[fill=gray!20, right,
text height=5\baselineskip,
text width=\paperwidth,
yshift=-2.2in % top margin++
] at (current page.north west) {};
\end{tikzpicture}
\fbox{\includegraphics[height=5\baselineskip]{image}}\hspace*{1cm}
\begin{minipage}[b]{.5\textwidth}\sffamily
list\\[\baselineskip]name\\tel\\email
\end{minipage}
\end{document}