How to change the default border color of fbox?

You can try this. It will also set the background to white, normally this should be not a problem.

\documentclass{article}

\usepackage{xcolor}

\renewcommand\fbox{\fcolorbox{red}{white}}
\begin{document}

\fbox{text}

\end{document}

enter image description here


Without setting the background color, one can save the current text color and apply it when the text of the \fbox is typeset, changing color for typesetting the rules.

\documentclass{article}
\usepackage{xcolor}
\usepackage{etoolbox}

\makeatletter
\let\cfbox\fbox
\let\c@frameb@x\@frameb@x
\pretocmd{\cfbox}
  {\leavevmode\begingroup\colorlet{currentcolor}{.}\color{red}}
  {}{}
\patchcmd\cfbox{\@frameb@x}{\c@frameb@x}{}{}
\patchcmd{\c@frameb@x}
  {\box\@tempboxa}
  {\color{currentcolor}\box\@tempboxa}
  {}{}
\apptocmd{\c@frameb@x}{\endgroup}{}{}
\makeatother

\begin{document}

text \cfbox{text} text

\fcolorbox{green}{blue}{text \cfbox{text} text}

\end{document}

I'd prefer a different command to redefining \fbox. If you instead want to use \fbox, just remove the \let\cfbox\fbox line and change \cfbox into \fbox in the remaining places.

enter image description here

Tags:

Color

Fbox