将颜色框右对齐到书封边缘的左侧

将颜色框右对齐到书封边缘的左侧

我想colorbox在 cls 中放置一个标题,bookcover该标题右对齐,并在边缘左侧留出边距。我可以使用tabularxcls来实现这一点article,但无法在 cls 中复制它bookcover。此外,如果halign=right取消注释,我会得到空白(无标题)。

\documentclass{article}
\usepackage{tabularx}
\usepackage{tcolorbox}

\begin{document}

\tcbset{colback=red!5!white,colframe=red!75!black}\begin{tcolorbox}[arc=0mm]This is a \textbf{tcolorbox}.\end{tcolorbox}

\newsavebox\mybox
\savebox\mybox
{

  \tcbset{colback=lightgray,colframe=red!75!black}
  \begin{tcolorbox}[width=0.3\textwidth,arc=0mm]
    \begin{flushright}
      This is a \textbf{tcolorbox}\par slighty shifted to the left of the body of text border\par
    \end{flushright}
  \end{tcolorbox}

}

\begin{flushright}
\begin{tabularx}{0.4\textwidth}{  l   @{\extracolsep{\fill}}}
\usebox{\mybox} 
\end{tabularx}  
\end{flushright}

\end{document}

文章

\documentclass[trimmed=true]{bookcover}
\usepackage{comment}
\usepackage{csquotes}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{keyfloat}
\usepackage{tabularx}
\usepackage{tcolorbox}
\usepackage{xparse}

\newsavebox\mybox
\savebox\mybox
{

  \begin{tcolorbox}[
    width=0.4\textwidth
    ,arc=0mm
    ,colback=white
    ,colframe=red!75!black
    ,coltext=black
%    ,halign=right
    ]
%    \begin{flushright}
    Make this \textbf{tcolorbox}\par
    slighty shifted to the left \par
    of the bookcover's border\par
    and the text withing right justified
%    \end{flushright}

  \end{tcolorbox}

}    

\begin{document}

\begin{bookcover}

  \bookcovercomponent{color}{bg whole}{blue}

  \bookcovercomponent{normal}{front}{ 

    \begin{center}
      \bfseries

      \vspace*{\fill}
      \begin{flushright}
        \begin{tabularx}{0.5\textwidth}{ l  @{\extracolsep{\fill}}}
          \usebox{\mybox} 
        \end{tabularx}  
      \end{flushright}

      \vspace*{\fill}

    \end{center}

  }


\end{bookcover}

\end{document}

封面

对齐=右

答案1

您可以使用enlarge right by={<somelength>}钥匙

\documentclass{article}
\usepackage{tabularx}
\usepackage[most]{tcolorbox}

\begin{document}
\tcbset{enhanced,colback=red!5!white,colframe=red!75!black,width=5cm}
\begin{flushright}
\begin{tcolorbox}[arc=0mm]
This is a \textbf{tcolorbox}.
\end{tcolorbox}

\begin{tcolorbox}[arc=0mm,enlarge right by=2cm]
This is a \textbf{tcolorbox}.
\end{tcolorbox}

\end{flushright}
\end{document} 

在此处输入图片描述

bookcover课堂应用

\documentclass[trimmed=true]{bookcover}
\usepackage[most]{tcolorbox}    
\tcbset{enhanced,colback=red!5!white,colframe=red!75!black,width=5cm}
\begin{document}
\begin{bookcover}
  \bookcovercomponent{color}{bg whole}{blue}
  \bookcovercomponent{normal}{front}{ 
\vspace*{\fill}
\begin{flushright}
\begin{tcolorbox}[arc=0mm]
This is a \textbf{tcolorbox}.
\end{tcolorbox}

\begin{tcolorbox}[arc=0mm,enlarge right by=2cm]
This is a \textbf{tcolorbox}.
\end{tcolorbox}
\end{flushright}
\vspace*{\fill}
}
\end{bookcover}

\end{document}

在此处输入图片描述

相关内容