11

How can I Tex this equation?

figure

I try to have exactly the same result but for the moment I only succeeded in having intersecting lines... Thanks!

  • 1
    Please show us the code you already have. Why make people type it for you and make the same 'errors' like you when trying to find some solution? – LaRiFaRi Apr 27 '15 at 14:18

4 Answers4

14

A way of achieving this:

\documentclass{article}
\begin{document}
  \[
    M = \left(
    \begin{array}{c|c}
      A & B\\
      \hline
      C & D
    \end{array}
    \right)
  \]
\end{document}

enter image description here

Franck Pastor
  • 18,756
13

You could use \midrule, a macro provided the booktabs package, inside an array environment. This setup will assure that the horizontal line will not intersect the vertical lines.

enter image description here

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\[
M = 
\left( \begin{array}{c|c}
   A & B \\
   \midrule
   C & D \\
\end{array}\right)
\]
\end{document}

Addendum to address a follow-up question: If A has to be replaced with a 3x4 matrix, say, I suggest you do so by using a matrix environment (provided by the amsmath package) for the matrix, as is done in the following example.

enter image description here

\documentclass{article}
\usepackage{booktabs}  % for '\midrule' macro
\usepackage{amsmath}   % for 'matrix' environment
\begin{document}
\[
M = 
\left( \begin{array}{@{}c|c@{}}
   \begin{matrix}
      a & b & c & d \\
      e & f & g & h \\
      i & j & k & l 
   \end{matrix} 
      & B \\
   \cmidrule[0.4pt]{1-2}
   C & D \\
\end{array} \right)
\]
\end{document}
Mico
  • 506,678
  • How to replace A, for instance, by a real matrix, a 3×4 matrix, say. @Mico – Hussein Eid Sep 24 '16 at 22:38
  • @HusseinEid - I've posted an addendum to address your question. – Mico Sep 24 '16 at 23:12
  • booktabs recommends that you never use vertical lines in a table. This suggests to me that while this may work at the moment, it may not work in a future version of the package. – Teepeemm Sep 25 '16 at 00:32
  • @Teepeemm - The booktabs package has been very stable since 2000. The updates since then have either just fixed bugs or added compatibility with packages such as longtable and colortbl. Do you have specific information regarding future changes to the booktabs package? – Mico Sep 25 '16 at 00:39
  • No information at all. But its author's denunciation of vertical lines makes me suspect that he hasn't even tried to test putting them into a table, and I wouldn't be surprised if vertical lines caused some sort of error down the road, either because of a slight change in booktabs, or because of a slightly different table that someone else is creating. – Teepeemm Sep 25 '16 at 01:06
  • @Teepeemm - I wholeheartedly agree with the view that vertical lines in tables should be avoided at (nearly...) all cost. Several years ago, I stopped using vertical lines in the tables of my own working papers, and as a result the tables look (and read!) much better. :-) The use case for the matrix is somewhat different, though: For some reason, the OP wants the horizontal line to be continuous and the vertical lines to be discontinuous. Achieving such a look is quite easy with booktabs and its \midrule and \cmidrule macros, but a lot more involved if one were to use other approaches. – Mico Sep 25 '16 at 07:22
3

Intercolumn space needs some adjustment but ...

\documentclass{article}
\begin{document}
  \[
    M = \left(\begin{array}{c@{}c@{}c}
      A & | & B\\
      \hline
      C & | & D
    \end{array}\right)
  \]
\end{document}

enter image description here

Ignasi
  • 136,588
-1

Try this:

$$ \left( \frac{A|B}{C|D} \right) $$

enter image description here