求助:Tikz节点无法应用左/右对齐的问题
解决LaTeX封面标题左对齐问题
你的问题根源在于\makecell命令默认是居中对齐,它会覆盖TikZ节点设置的align=left属性,导致标题始终居中。下面提供两种直接有效的解决方法:
方法一:修改makecell的对齐参数
给\makecell添加[l]参数指定左对齐,让单元格内的内容跟随节点的对齐设置:
\usepackage{tikz} \usepackage{makecell} \begin{titlepage} \setlength{\parindent}{0pt} \begin{figure} \begin{tikzpicture}[remember picture,overlay] \node at (current page.center) {\includegraphics[scale=0.2]{example-image-10x16}}; \node[fill=white, scale=2, text=red, text width=94mm, align=left] at ([xshift=7mm,yshift=30mm]current page.center) {\makecell[l]{\textbf{The title goes here and it is very}\\textbf{long so it covers two lines}\\Xhline{2\arrayrulewidth}\\[-18pt]\scalebox{.35}{\textbf{\fontfamily{phv}\selectfont DEPARTMENT OF SOME ENGINEERING DISCIPLINE $\vert$ MY UNIVERSITY}}\\[-7pt]\scalebox{.35}{\textbf{\fontfamily{phv}\selectfont MY NAME HERE $\vert$ NAME OF PROGRAM}}}}; \end{tikzpicture} \end{figure} \end{titlepage}
方法二:移除makecell直接利用节点属性
你已经给TikZ节点设置了text width=94mm和align=left,完全可以去掉\makecell,直接用\\换行,节点会自动处理文本的左对齐和换行:
\usepackage{tikz} \usepackage{makecell} \begin{titlepage} \setlength{\parindent}{0pt} \begin{figure} \begin{tikzpicture}[remember picture,overlay] \node at (current page.center) {\includegraphics[scale=0.2]{example-image-10x16}}; \node[fill=white, scale=2, text=red, text width=94mm, align=left] at ([xshift=7mm,yshift=30mm]current page.center) {\textbf{The title goes here and it is very}\\textbf{long so it covers two lines}\\Xhline{2\arrayrulewidth}\\[-18pt]\scalebox{.35}{\textbf{\fontfamily{phv}\selectfont DEPARTMENT OF SOME ENGINEERING DISCIPLINE $\vert$ MY UNIVERSITY}}\\[-7pt]\scalebox{.35}{\textbf{\fontfamily{phv}\selectfont MY NAME HERE $\vert$ NAME OF PROGRAM}}}; \end{tikzpicture} \end{figure} \end{titlepage}
两种方法都能实现标题的左对齐,你可以根据习惯选择其中一种。
内容的提问来源于stack exchange,提问作者Max
相关产品推荐
相关产品推荐

