On May 12, 2022, OneNote 2021 in Microsoft 365 was updated to version 2206 (June 2022).
Added ruler functionality to line with strokes
This feature is available in OneNote for Windows 10.
Microsoft promised to port the features of OneNote for Windows 10 to OneNote 2021.
Now, the ruler is one of those features.
The ruler function is in the "Drawing" tab -> "Stencils" group.